Skip to content

Commit 9d27059

Browse files
committed
fix constants
1 parent 3938af8 commit 9d27059

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/libcollections/btree.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ use {Mutable, MutableMap, Map, MutableSeq};
2424
/// "Order" of the B-tree, from which all other properties are derived
2525
static B: uint = 6;
2626
/// Maximum number of elements in a node
27-
static capacity: uint = 2 * B - 1;
27+
static CAPACITY: uint = 2 * B - 1;
2828
/// Minimum number of elements in a node
29-
static min_load: uint = B - 1;
29+
static MIN_LOAD: uint = B - 1;
3030
/// Maximum number of children in a node
31-
static edge_capacity: uint = capacity + 1;
31+
static EDGE_CAPACITY: uint = CAPACITY + 1;
3232
/// 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;
3434

3535
/// Represents a search path for mutating
3636
type SearchStack<K,V> = Vec<(*mut Node<K,V>, uint)>;
@@ -44,9 +44,9 @@ enum InsertionResult<K,V>{
4444
/// A B-Tree Node
4545
struct Node<K,V> {
4646
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],
5050
}
5151

5252

@@ -424,7 +424,7 @@ impl<K,V> BTree<K,V> {
424424
let (node_ptr, index) = stack.pop().unwrap();
425425
let node = &mut *node_ptr;
426426
let (_key, value) = node.remove_as_leaf(index);
427-
let underflow = node.length < min_load;
427+
let underflow = node.length < MIN_LOAD;
428428
(value, underflow)
429429
};
430430

@@ -447,7 +447,7 @@ impl<K,V> BTree<K,V> {
447447
unsafe {
448448
let parent = &mut *parent_ptr;
449449
parent.handle_underflow(index);
450-
underflow = parent.length < min_load;
450+
underflow = parent.length < MIN_LOAD;
451451
}
452452
} else {
453453
// All done!
@@ -495,7 +495,7 @@ impl<K,V> Node<K,V> {
495495
/// If the node is full, we have to split it.
496496
fn insert_as_leaf(&mut self, index: uint, key: K, value: V) -> InsertionResult<K,V> {
497497
let len = self.length;
498-
if len < capacity {
498+
if len < CAPACITY {
499499
// The element can fit, just insert it
500500
self.insert_fit_as_leaf(index, key, value);
501501
Fit
@@ -519,7 +519,7 @@ impl<K,V> Node<K,V> {
519519
fn insert_as_internal(&mut self, index: uint, key: K, value: V, right: Box<Node<K,V>>)
520520
-> InsertionResult<K,V> {
521521
let len = self.length;
522-
if len < capacity {
522+
if len < CAPACITY {
523523
// The element can fit, just insert it
524524
self.insert_fit_as_internal(index, key, value, right);
525525
Fit
@@ -562,14 +562,14 @@ impl<K,V> Node<K,V> {
562562
fn split(&mut self) -> (K, V, Box<Node<K, V>>) {
563563
let mut right = box Node::new();
564564

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);
567567
// 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);
569569

570570
// 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;
573573

574574
// But we're gonna pop one off the end of the left one, so subtract one
575575
self.length = left_len - 1;
@@ -611,7 +611,7 @@ impl<K,V> Node<K,V> {
611611
// but merge left and right if left is low too.
612612
let mut left = self.edges[underflowed_child_index - 1].take().unwrap();
613613
let left_len = left.length;
614-
if left_len > min_load {
614+
if left_len > MIN_LOAD {
615615
// Steal! Stealing is roughly analagous to a binary tree rotation.
616616
// In this case, we're "rotating" right.
617617

@@ -663,7 +663,7 @@ impl<K,V> Node<K,V> {
663663
// but merge left and right if right is low too.
664664
let mut right = self.edges[underflowed_child_index + 1].take().unwrap();
665665
let right_len = right.length;
666-
if right_len > min_load {
666+
if right_len > MIN_LOAD {
667667
// Steal! Stealing is roughly analagous to a binary tree rotation.
668668
// In this case, we're "rotating" left.
669669

@@ -781,7 +781,7 @@ fn remove_and_shift<T>(slice: &mut [Option<T>], index: uint) -> Option<T> {
781781
result
782782
}
783783

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,
785785
/// (which should be full) and put them at the start of right (which should be empty)
786786
fn steal_last<T>(left: &mut[T], right: &mut[T], amount: uint) {
787787
// Is there a better way to do this?

0 commit comments

Comments
 (0)