@@ -24,13 +24,13 @@ use {Mutable, MutableMap, Map, MutableSeq};
24
24
/// "Order" of the B-tree, from which all other properties are derived
25
25
static B : uint = 6 ;
26
26
/// Maximum number of elements in a node
27
- static capacity : uint = 2 * B - 1 ;
27
+ static CAPACITY : uint = 2 * B - 1 ;
28
28
/// Minimum number of elements in a node
29
- static min_load : uint = B - 1 ;
29
+ static MIN_LOAD : uint = B - 1 ;
30
30
/// Maximum number of children in a node
31
- static edge_capacity : uint = capacity + 1 ;
31
+ static EDGE_CAPACITY : uint = CAPACITY + 1 ;
32
32
/// Amount to take off the tail of a node being split
33
- static split_len : uint = B - 1 ;
33
+ static SPLIT_LEN : uint = B - 1 ;
34
34
35
35
/// Represents a search path for mutating
36
36
type SearchStack < K , V > = Vec < ( * mut Node < K , V > , uint ) > ;
@@ -44,9 +44,9 @@ enum InsertionResult<K,V>{
44
44
/// A B-Tree Node
45
45
struct Node < K , V > {
46
46
length : uint ,
47
- keys : [ Option < K > , ..capacity ] ,
48
- edges : [ Option < Box < Node < K , V > > > , ..edge_capacity ] ,
49
- vals : [ Option < V > , ..capacity ] ,
47
+ keys : [ Option < K > , ..CAPACITY ] ,
48
+ edges : [ Option < Box < Node < K , V > > > , ..EDGE_CAPACITY ] ,
49
+ vals : [ Option < V > , ..CAPACITY ] ,
50
50
}
51
51
52
52
@@ -424,7 +424,7 @@ impl<K,V> BTree<K,V> {
424
424
let ( node_ptr, index) = stack. pop ( ) . unwrap ( ) ;
425
425
let node = & mut * node_ptr;
426
426
let ( _key, value) = node. remove_as_leaf ( index) ;
427
- let underflow = node. length < min_load ;
427
+ let underflow = node. length < MIN_LOAD ;
428
428
( value, underflow)
429
429
} ;
430
430
@@ -447,7 +447,7 @@ impl<K,V> BTree<K,V> {
447
447
unsafe {
448
448
let parent = & mut * parent_ptr;
449
449
parent. handle_underflow ( index) ;
450
- underflow = parent. length < min_load ;
450
+ underflow = parent. length < MIN_LOAD ;
451
451
}
452
452
} else {
453
453
// All done!
@@ -495,7 +495,7 @@ impl<K,V> Node<K,V> {
495
495
/// If the node is full, we have to split it.
496
496
fn insert_as_leaf ( & mut self , index : uint , key : K , value : V ) -> InsertionResult < K , V > {
497
497
let len = self . length ;
498
- if len < capacity {
498
+ if len < CAPACITY {
499
499
// The element can fit, just insert it
500
500
self . insert_fit_as_leaf ( index, key, value) ;
501
501
Fit
@@ -519,7 +519,7 @@ impl<K,V> Node<K,V> {
519
519
fn insert_as_internal ( & mut self , index : uint , key : K , value : V , right : Box < Node < K , V > > )
520
520
-> InsertionResult < K , V > {
521
521
let len = self . length ;
522
- if len < capacity {
522
+ if len < CAPACITY {
523
523
// The element can fit, just insert it
524
524
self . insert_fit_as_internal ( index, key, value, right) ;
525
525
Fit
@@ -562,14 +562,14 @@ impl<K,V> Node<K,V> {
562
562
fn split ( & mut self ) -> ( K , V , Box < Node < K , V > > ) {
563
563
let mut right = box Node :: new ( ) ;
564
564
565
- steal_last ( self . vals . as_mut_slice ( ) , right. vals . as_mut_slice ( ) , split_len ) ;
566
- steal_last ( self . keys . as_mut_slice ( ) , right. keys . as_mut_slice ( ) , split_len ) ;
565
+ steal_last ( self . vals . as_mut_slice ( ) , right. vals . as_mut_slice ( ) , SPLIT_LEN ) ;
566
+ steal_last ( self . keys . as_mut_slice ( ) , right. keys . as_mut_slice ( ) , SPLIT_LEN ) ;
567
567
// FIXME(Gankro): This isn't necessary for leaf nodes
568
- steal_last ( self . edges . as_mut_slice ( ) , right. edges . as_mut_slice ( ) , split_len + 1 ) ;
568
+ steal_last ( self . edges . as_mut_slice ( ) , right. edges . as_mut_slice ( ) , SPLIT_LEN + 1 ) ;
569
569
570
570
// How much each node got
571
- let left_len = capacity - split_len ;
572
- let right_len = split_len ;
571
+ let left_len = CAPACITY - SPLIT_LEN ;
572
+ let right_len = SPLIT_LEN ;
573
573
574
574
// But we're gonna pop one off the end of the left one, so subtract one
575
575
self . length = left_len - 1 ;
@@ -611,7 +611,7 @@ impl<K,V> Node<K,V> {
611
611
// but merge left and right if left is low too.
612
612
let mut left = self . edges [ underflowed_child_index - 1 ] . take ( ) . unwrap ( ) ;
613
613
let left_len = left. length ;
614
- if left_len > min_load {
614
+ if left_len > MIN_LOAD {
615
615
// Steal! Stealing is roughly analagous to a binary tree rotation.
616
616
// In this case, we're "rotating" right.
617
617
@@ -663,7 +663,7 @@ impl<K,V> Node<K,V> {
663
663
// but merge left and right if right is low too.
664
664
let mut right = self . edges [ underflowed_child_index + 1 ] . take ( ) . unwrap ( ) ;
665
665
let right_len = right. length ;
666
- if right_len > min_load {
666
+ if right_len > MIN_LOAD {
667
667
// Steal! Stealing is roughly analagous to a binary tree rotation.
668
668
// In this case, we're "rotating" left.
669
669
@@ -781,7 +781,7 @@ fn remove_and_shift<T>(slice: &mut [Option<T>], index: uint) -> Option<T> {
781
781
result
782
782
}
783
783
784
- /// Subroutine for splitting a node. Put the `split_len ` last elements from left,
784
+ /// Subroutine for splitting a node. Put the `SPLIT_LEN ` last elements from left,
785
785
/// (which should be full) and put them at the start of right (which should be empty)
786
786
fn steal_last < T > ( left : & mut [ T ] , right : & mut [ T ] , amount : uint ) {
787
787
// Is there a better way to do this?
0 commit comments