Created
June 4, 2013 20:49
-
-
Save rubber-duck/5709465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static node_size : uint = 32; | |
struct HashArrayMappedTrie<T> { | |
root : ~Node<T>, | |
length : uint | |
} | |
enum Node<T> { | |
Values([T]), | |
Children([@Node<T>, ..node_size]), | |
} | |
fn from_vec<T>(source : @[T]) -> ~Node<T> { | |
// if source is larger than node need to chunk it to child nodes | |
if source.len() > node_size { | |
// calculate closest power of node_size to source.len() | |
let chunk_size = node_size.to_float().pow(source.len().to_float().log(node_size.to_float()).trunc()) as uint; | |
// split source in chunk_size and recursively call from_vec on each chunk | |
~Children(uint::range(0, source.len() / chunk_size).map(|chunk| from_vec(vec::const_slice(source, chunk * chunk_size, (chunk + 1) * chunk_size)))) | |
} else { | |
// values array doesn't need to be of node_size length, it can be smaller | |
~Values(source.copy()) | |
} | |
} | |
fn main() { | |
let tree = from_vec<int>([1, .. 128]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main.rs:19:81: 19:97 error: unresolved name | |
main.rs:19 ~Children(uint::range(0, source.len() / chunk_size).map(|chunk| from_vec(vec::const_slice(source, chunk * chunk_size, (chunk + 1) * chunk_size)))) | |
^~~~~~~~~~~~~~~~ | |
main.rs:19:81: 19:97 error: use of undeclared module `vec` | |
main.rs:19 ~Children(uint::range(0, source.len() / chunk_size).map(|chunk| from_vec(vec::const_slice(source, chunk * chunk_size, (chunk + 1) * chunk_size)))) | |
^~~~~~~~~~~~~~~~ | |
main.rs:19:81: 19:97 error: unresolved name `vec::const_slice`. | |
main.rs:19 ~Children(uint::range(0, source.len() / chunk_size).map(|chunk| from_vec(vec::const_slice(source, chunk * chunk_size, (chunk + 1) * chunk_size)))) | |
^~~~~~~~~~~~~~~~ | |
main.rs:19:18: 19:29 error: unresolved name | |
main.rs:19 ~Children(uint::range(0, source.len() / chunk_size).map(|chunk| from_vec(vec::const_slice(source, chunk * chunk_size, (chunk + 1) * chunk_size)))) | |
^~~~~~~~~~~ | |
main.rs:19:18: 19:29 error: use of undeclared module `uint` | |
main.rs:19 ~Children(uint::range(0, source.len() / chunk_size).map(|chunk| from_vec(vec::const_slice(source, chunk * chunk_size, (chunk + 1) * chunk_size)))) | |
^~~~~~~~~~~ | |
main.rs:19:18: 19:29 error: unresolved name `uint::range`. | |
main.rs:19 ~Children(uint::range(0, source.len() / chunk_size).map(|chunk| from_vec(vec::const_slice(source, chunk * chunk_size, (chunk + 1) * chunk_size)))) | |
^~~~~~~~~~~ | |
main.rs:28:24: 28:27 error: unresolved name `int`. | |
main.rs:28 let tree = from_vec<int>([1, .. 128]); | |
^~~ | |
error: aborting due to 7 previous errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment