@@ -69,6 +69,7 @@ impl<K: Eq + Ord, V : Eq> BTree<K, V> {
6969 }
7070
7171 /// Return the number of keys that can be stored in the b-tree node.
72+ #[ inline]
7273 pub fn capacity ( & self ) -> uint { BTREE_KEYS_UBOUND }
7374
7475 /// Return a reference to the value corresponding to the key.
@@ -109,8 +110,6 @@ impl<K: Eq + Ord, V : Eq> BTree<K, V> {
109110 /// TODO: return true if the key did not already exist. Determine if the
110111 /// key is new is not supported at the moment.
111112 pub fn insert ( & mut self , key : K , value : V ) -> bool {
112-
113-
114113 if self . used == self . capacity ( ) {
115114 let mut child = BTree :: new ( ) ;
116115
@@ -176,40 +175,25 @@ fn find_node<'r, K: Eq + Ord, V>(tree: &'r mut BTree<K, V>,
176175}
177176
178177fn split_child < K : Eq + Ord , V : Eq > ( tree : & mut BTree < K , V > , pos : uint ) {
179- //println(fmt!("== before split: == \n%s", tree.to_str()));
180-
181178 let t = BTREE_MIN_DEGREE ;
182179
183180 // Make a free slot in the parent node for the to-be-inserted key.
184181 // Move the median key from the left node to the parent node. The median
185182 // key separates the left and right node.
186183 let mut i = tree. used ;
187184
188- //printf!("i = %?; pos = %?\n", i, pos);
189- //printf!("tree.keys: %?\n", tree.keys);
190- //printf!("tree.nodes: %?\n", tree.nodes);
191-
192185 while i > pos {
193186 tree. nodes . swap ( i, i + 1 ) ;
194187 tree. keys . swap ( i - 1 , i) ;
195188 i -= 1 ;
196189 }
197190
198- //printf!("tree.keys: %?\n", tree.keys);
199- //printf!("tree.nodes: %?\n", tree.nodes);
200-
201191 let right = match tree. nodes [ pos] {
202192 Some ( TreeNode { value : ref mut left } ) => {
203193 let mut right = BTree :: new ( ) ;
204194
205195 let mut i = 0 ;
206196
207- //printf!("left.keys: %?\n", left.keys);
208- //printf!("left.nodes: %?\n", left.nodes);
209-
210- //printf!("right.keys: %?\n", right.keys);
211- //printf!("right.nodes: %?\n", right.nodes);
212-
213197 // Move the larger `t - 1' keys and corresponding `t' nodes from
214198 // the left node to the right node.
215199 while i < t - 1 {
@@ -228,30 +212,21 @@ fn split_child<K: Eq + Ord, V: Eq>(tree: &mut BTree<K, V>, pos: uint) {
228212 }
229213 //}
230214
231- assert ! ( tree. keys[ pos] . is_none( ) ) ;
215+ // assert!(tree.keys[pos].is_none());
232216 util:: swap ( & mut tree. keys [ pos] , & mut left. keys [ t - 1 ] ) ;
233217
234218 left. used = t - 1 ;
235219 right. used = t - 1 ;
236220
237- //printf!("left.keys: %?\n", left.keys);
238- //printf!("left.nodes: %?\n", left.nodes);
239-
240- //printf!("right.keys: %?\n", right.keys);
241- //printf!("right.nodes: %?\n", right.nodes);
242-
243221 right
244222 }
245223 _ => fail ! ( "unreachable path: tree.nodes[pos] should be a TreeNode" ) ,
246224 } ;
247225
248- assert ! ( tree. nodes[ pos + 1 ] . is_none( ) ) ;
226+ // assert!(tree.nodes[pos + 1].is_none());
249227 tree. nodes [ pos + 1 ] = Some ( TreeNode { value : right } ) ;
250228
251229 tree. used += 1 ;
252-
253- //println(fmt!("tree: %?", tree));
254- //println(fmt!("== after split: == \n%s", tree.to_str()));
255230}
256231
257232fn is_leaf < K , V > ( tree : & mut BTree < K , V > ) -> bool {
@@ -263,19 +238,13 @@ fn is_leaf<K, V>(tree: &mut BTree<K, V>) -> bool {
263238
264239fn insert_non_full < K : Eq + Ord , V : Eq > ( tree : & mut BTree < K , V > , key : K ,
265240 value : V ) -> bool {
266- //println(fmt!("== before insert_non_full: == \n%s", tree.to_str()));
267-
268241 if tree. used == 0 || is_leaf ( tree) {
269242 let pos = find_node_pos ( tree, & key) ;
270243
271244 let new_key = tree. keys [ pos] . is_none ( )
272245 || tree. keys [ pos] . get_ref ( ) != & key;
273246
274247 if new_key {
275- //println(fmt!("tree.keys: %?", tree.keys));
276- //println(fmt!("tree.nodes: %?", tree.nodes));
277- //println(fmt!("pos = %?; key = %?", pos, key));
278-
279248 let mut i = tree. used ;
280249
281250 if i > 0 {
@@ -299,8 +268,6 @@ fn insert_non_full<K: Eq + Ord, V: Eq>(tree: &mut BTree<K, V>, key: K,
299268 util:: replace ( & mut tree. keys [ pos] , Some ( key) ) ;
300269 util:: replace ( & mut tree. nodes [ pos] , Some ( TreeLeaf { value : value } ) ) ;
301270
302- //println(fmt!("== after insert_non_full: == \n%s", tree.to_str()));
303-
304271 new_key
305272 } else {
306273 let mut pos = find_node_pos ( tree, & key) ;
@@ -689,7 +656,7 @@ mod test_btree {
689656
690657 let mut random_keys = ~[ ] ;
691658 for std:: uint:: range( 0 , iterations) |k| { random_keys. push( k) ; }
692- rng. shuffle ( random_keys) ;
659+ rng. shuffle_mut ( random_keys) ;
693660
694661 let mut i = 0 ;
695662
0 commit comments