Last active
December 19, 2015 09:39
-
-
Save smvv/5934520 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
| // The number of keys is chosen to vary between d and 2d, where d is the | |
| // minimum number of keys and d+1 is the minimum degree (branching factor) of | |
| // the tree. In this case, d = 2 which results in degree = 5. | |
| static BTreeDegree : uint = 5; | |
| pub struct BTree<K, V> { | |
| priv pairs: [NodeContent<K, V>, ..BTreeDegree], | |
| } | |
| enum NodeContent<K, V> { | |
| None, | |
| BTreeNode { key: K, value: ~BTree<K, V> }, | |
| BTreeValue { key: K, value: V }, | |
| } | |
| impl<K: Eq + Ord + TotalOrd, V> BTree<K, V> { | |
| pub fn new() -> BTree<K, V> { | |
| BTree { pairs: [None, ..BTreeDegree] } | |
| } | |
| pub fn insert(&mut self, key: K, value: V) { | |
| fail!("fail!"); | |
| } | |
| } | |
| fn main() { | |
| let mut tree = BTree { pairs: [None, ..BTreeDegree] }; | |
| tree.insert(0, "hi"); | |
| tree.insert(1, "bye"); | |
| } | |
| /* | |
| :!rustc test.rs | |
| test.rs:18:24: 18:28 error: copying a value of non-copyable type `NodeContent<T,U>` | |
| test.rs:18 BTree { pairs: [None, ..BTreeDegree] } | |
| ^~~~ | |
| test.rs:18:24: 18:28 note: repeated element will be copied | |
| test.rs:18 BTree { pairs: [None, ..BTreeDegree] } | |
| ^~~~ | |
| error: aborting due to previous error | |
| */ |
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
| // The number of keys is chosen to vary between d and 2d, where d is the | |
| // minimum number of keys and d+1 is the minimum degree (branching factor) of | |
| // the tree. In this case, d = 2 which results in degree = 5. | |
| static BTreeDegree : uint = 5; | |
| pub struct BTree<K, V> { | |
| priv pairs: [NodeContent<K, V>, ..BTreeDegree], | |
| } | |
| impl<K: Eq + Ord + TotalOrd, V> Clone for BTree<K, V> { | |
| #[inline] | |
| fn clone(&self) -> BTree<K, V> { | |
| //BTree { pairs: *self.pairs.clone() } | |
| BTree::new() | |
| } | |
| } | |
| #[deriving(Clone)] | |
| enum NodeContent<K, V> { | |
| None, | |
| BTreeNode { key: K, value: ~BTree<K, V> }, | |
| BTreeValue { key: K, value: V }, | |
| } | |
| impl<K: Eq + Ord + TotalOrd, V> BTree<K, V> { | |
| pub fn new() -> BTree<K, V> { | |
| BTree { pairs: [None, ..BTreeDegree] } | |
| } | |
| pub fn insert(&mut self, key: K, value: V) { | |
| fail!("fail!"); | |
| } | |
| } | |
| fn main() { | |
| let mut tree = BTree { pairs: [None, ..BTreeDegree] }; | |
| tree.insert(0, "hi"); | |
| tree.insert(1, "bye"); | |
| } | |
| /* | |
| :!rustc test.rs | |
| test.rs:18:11: 18:16 error: failed to find an implementation of trait std::cmp::Eq for T | |
| test.rs:18 #[deriving(Clone)] | |
| ^~~~~ | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment