@@ -34,9 +34,9 @@ pub enum InsertionResult<K, V> {
34
34
/// Represents the result of a search for a key in a single node
35
35
pub enum SearchResult < NodeRef > {
36
36
/// The element was found at the given index
37
- Found ( Handle < NodeRef , KV , LeafOrInternal > ) ,
37
+ Found ( Handle < NodeRef , handle :: KV , handle :: LeafOrInternal > ) ,
38
38
/// The element wasn't found, but if it's anywhere, it must be beyond this edge
39
- GoDown ( Handle < NodeRef , Edge , LeafOrInternal > ) ,
39
+ GoDown ( Handle < NodeRef , handle :: Edge , handle :: LeafOrInternal > ) ,
40
40
}
41
41
42
42
/// A B-Tree Node. We keep keys/edges/values separate to optimize searching for keys.
@@ -494,12 +494,16 @@ pub struct Handle<NodeRef, Type, NodeType> {
494
494
index : uint
495
495
}
496
496
497
- pub enum KV { }
498
- pub enum Edge { }
497
+ pub mod handle {
498
+ // Handle types.
499
+ pub enum KV { }
500
+ pub enum Edge { }
499
501
500
- pub enum LeafOrInternal { }
501
- pub enum Leaf { }
502
- pub enum Internal { }
502
+ // Handle node types.
503
+ pub enum LeafOrInternal { }
504
+ pub enum Leaf { }
505
+ pub enum Internal { }
506
+ }
503
507
504
508
impl < K : Ord , V > Node < K , V > {
505
509
/// Searches for the given key in the node. If it finds an exact match,
@@ -625,7 +629,7 @@ impl<K, V, Type, NodeType> Handle<*mut Node<K, V>, Type, NodeType> {
625
629
}
626
630
}
627
631
628
- impl < ' a , K : ' a , V : ' a > Handle < & ' a Node < K , V > , Edge , Internal > {
632
+ impl < ' a , K : ' a , V : ' a > Handle < & ' a Node < K , V > , handle :: Edge , handle :: Internal > {
629
633
/// Turns the handle into a reference to the edge it points at. This is necessary because the
630
634
/// returned pointer has a larger lifetime than what would be returned by `edge` or `edge_mut`,
631
635
/// making it more suitable for moving down a chain of nodes.
@@ -636,7 +640,7 @@ impl<'a, K: 'a, V: 'a> Handle<&'a Node<K, V>, Edge, Internal> {
636
640
}
637
641
}
638
642
639
- impl < ' a , K : ' a , V : ' a > Handle < & ' a mut Node < K , V > , Edge , Internal > {
643
+ impl < ' a , K : ' a , V : ' a > Handle < & ' a mut Node < K , V > , handle :: Edge , handle :: Internal > {
640
644
/// Turns the handle into a mutable reference to the edge it points at. This is necessary
641
645
/// because the returned pointer has a larger lifetime than what would be returned by
642
646
/// `edge_mut`, making it more suitable for moving down a chain of nodes.
@@ -647,7 +651,7 @@ impl<'a, K: 'a, V: 'a> Handle<&'a mut Node<K, V>, Edge, Internal> {
647
651
}
648
652
}
649
653
650
- impl < K , V , NodeRef : Deref < Node < K , V > > > Handle < NodeRef , Edge , Internal > {
654
+ impl < K , V , NodeRef : Deref < Node < K , V > > > Handle < NodeRef , handle :: Edge , handle :: Internal > {
651
655
// This doesn't exist because there are no uses for it,
652
656
// but is fine to add, analagous to edge_mut.
653
657
//
@@ -657,11 +661,11 @@ impl<K, V, NodeRef: Deref<Node<K, V>>> Handle<NodeRef, Edge, Internal> {
657
661
}
658
662
659
663
pub enum ForceResult < NodeRef , Type > {
660
- Leaf ( Handle < NodeRef , Type , Leaf > ) ,
661
- Internal ( Handle < NodeRef , Type , Internal > )
664
+ Leaf ( Handle < NodeRef , Type , handle :: Leaf > ) ,
665
+ Internal ( Handle < NodeRef , Type , handle :: Internal > )
662
666
}
663
667
664
- impl < K , V , NodeRef : Deref < Node < K , V > > , Type > Handle < NodeRef , Type , LeafOrInternal > {
668
+ impl < K , V , NodeRef : Deref < Node < K , V > > , Type > Handle < NodeRef , Type , handle :: LeafOrInternal > {
665
669
/// Figure out whether this handle is pointing to something in a leaf node or to something in
666
670
/// an internal node, clarifying the type according to the result.
667
671
pub fn force ( self ) -> ForceResult < NodeRef , Type > {
@@ -679,7 +683,7 @@ impl<K, V, NodeRef: Deref<Node<K, V>>, Type> Handle<NodeRef, Type, LeafOrInterna
679
683
}
680
684
}
681
685
682
- impl < K , V , NodeRef : DerefMut < Node < K , V > > > Handle < NodeRef , Edge , Leaf > {
686
+ impl < K , V , NodeRef : DerefMut < Node < K , V > > > Handle < NodeRef , handle :: Edge , handle :: Leaf > {
683
687
/// Tries to insert this key-value pair at the given index in this leaf node
684
688
/// If the node is full, we have to split it.
685
689
///
@@ -711,7 +715,7 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, Edge, Leaf> {
711
715
}
712
716
}
713
717
714
- impl < K , V , NodeRef : DerefMut < Node < K , V > > > Handle < NodeRef , Edge , Internal > {
718
+ impl < K , V , NodeRef : DerefMut < Node < K , V > > > Handle < NodeRef , handle :: Edge , handle :: Internal > {
715
719
/// Returns a mutable reference to the edge pointed-to by this handle. This should not be
716
720
/// confused with `node`, which references the parent node of what is returned here.
717
721
pub fn edge_mut ( & mut self ) -> & mut Node < K , V > {
@@ -794,11 +798,11 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, Edge, Internal> {
794
798
}
795
799
}
796
800
797
- impl < K , V , NodeRef : DerefMut < Node < K , V > > , NodeType > Handle < NodeRef , Edge , NodeType > {
801
+ impl < K , V , NodeRef : DerefMut < Node < K , V > > , NodeType > Handle < NodeRef , handle :: Edge , NodeType > {
798
802
/// Gets the handle pointing to the key/value pair just to the left of the pointed-to edge.
799
803
/// This is unsafe because the handle might point to the first edge in the node, which has no
800
804
/// pair to its left.
801
- unsafe fn left_kv < ' a > ( & ' a mut self ) -> Handle < & ' a mut Node < K , V > , KV , NodeType > {
805
+ unsafe fn left_kv < ' a > ( & ' a mut self ) -> Handle < & ' a mut Node < K , V > , handle :: KV , NodeType > {
802
806
Handle {
803
807
node : & mut * self . node ,
804
808
index : self . index - 1
@@ -808,15 +812,15 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, Edge, NodeTy
808
812
/// Gets the handle pointing to the key/value pair just to the right of the pointed-to edge.
809
813
/// This is unsafe because the handle might point to the last edge in the node, which has no
810
814
/// pair to its right.
811
- unsafe fn right_kv < ' a > ( & ' a mut self ) -> Handle < & ' a mut Node < K , V > , KV , NodeType > {
815
+ unsafe fn right_kv < ' a > ( & ' a mut self ) -> Handle < & ' a mut Node < K , V > , handle :: KV , NodeType > {
812
816
Handle {
813
817
node : & mut * self . node ,
814
818
index : self . index
815
819
}
816
820
}
817
821
}
818
822
819
- impl < ' a , K : ' a , V : ' a , NodeType > Handle < & ' a Node < K , V > , KV , NodeType > {
823
+ impl < ' a , K : ' a , V : ' a , NodeType > Handle < & ' a Node < K , V > , handle :: KV , NodeType > {
820
824
/// Turns the handle into references to the key and value it points at. This is necessary
821
825
/// because the returned pointers have larger lifetimes than what would be returned by `key`
822
826
/// or `val`.
@@ -831,7 +835,7 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a Node<K, V>, KV, NodeType> {
831
835
}
832
836
}
833
837
834
- impl < ' a , K : ' a , V : ' a , NodeType > Handle < & ' a mut Node < K , V > , KV , NodeType > {
838
+ impl < ' a , K : ' a , V : ' a , NodeType > Handle < & ' a mut Node < K , V > , handle :: KV , NodeType > {
835
839
/// Turns the handle into mutable references to the key and value it points at. This is
836
840
/// necessary because the returned pointers have larger lifetimes than what would be returned
837
841
/// by `key_mut` or `val_mut`.
@@ -848,15 +852,16 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node<K, V>, KV, NodeType> {
848
852
/// Convert this handle into one pointing at the edge immediately to the left of the key/value
849
853
/// pair pointed-to by this handle. This is useful because it returns a reference with larger
850
854
/// lifetime than `left_edge`.
851
- pub fn into_left_edge ( self ) -> Handle < & ' a mut Node < K , V > , Edge , NodeType > {
855
+ pub fn into_left_edge ( self ) -> Handle < & ' a mut Node < K , V > , handle :: Edge , NodeType > {
852
856
Handle {
853
857
node : & mut * self . node ,
854
858
index : self . index
855
859
}
856
860
}
857
861
}
858
862
859
- impl < ' a , K : ' a , V : ' a , NodeRef : Deref < Node < K , V > > + ' a , NodeType > Handle < NodeRef , KV , NodeType > {
863
+ impl < ' a , K : ' a , V : ' a , NodeRef : Deref < Node < K , V > > + ' a , NodeType > Handle < NodeRef , handle:: KV ,
864
+ NodeType > {
860
865
// These are fine to include, but are currently unneeded.
861
866
//
862
867
// /// Returns a reference to the key pointed-to by this handle. This doesn't return a
@@ -874,7 +879,8 @@ impl<'a, K: 'a, V: 'a, NodeRef: Deref<Node<K, V>> + 'a, NodeType> Handle<NodeRef
874
879
// }
875
880
}
876
881
877
- impl < ' a , K : ' a , V : ' a , NodeRef : DerefMut < Node < K , V > > + ' a , NodeType > Handle < NodeRef , KV , NodeType > {
882
+ impl < ' a , K : ' a , V : ' a , NodeRef : DerefMut < Node < K , V > > + ' a , NodeType > Handle < NodeRef , handle:: KV ,
883
+ NodeType > {
878
884
/// Returns a mutable reference to the key pointed-to by this handle. This doesn't return a
879
885
/// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
880
886
/// handle.
@@ -890,10 +896,10 @@ impl<'a, K: 'a, V: 'a, NodeRef: DerefMut<Node<K, V>> + 'a, NodeType> Handle<Node
890
896
}
891
897
}
892
898
893
- impl < K , V , NodeRef : DerefMut < Node < K , V > > , NodeType > Handle < NodeRef , KV , NodeType > {
899
+ impl < K , V , NodeRef : DerefMut < Node < K , V > > , NodeType > Handle < NodeRef , handle :: KV , NodeType > {
894
900
/// Gets the handle pointing to the edge immediately to the left of the key/value pair pointed
895
901
/// to by this handle.
896
- pub fn left_edge < ' a > ( & ' a mut self ) -> Handle < & ' a mut Node < K , V > , Edge , NodeType > {
902
+ pub fn left_edge < ' a > ( & ' a mut self ) -> Handle < & ' a mut Node < K , V > , handle :: Edge , NodeType > {
897
903
Handle {
898
904
node : & mut * self . node ,
899
905
index : self . index
@@ -902,15 +908,15 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, KV, NodeType
902
908
903
909
/// Gets the handle pointing to the edge immediately to the right of the key/value pair pointed
904
910
/// to by this handle.
905
- pub fn right_edge < ' a > ( & ' a mut self ) -> Handle < & ' a mut Node < K , V > , Edge , NodeType > {
911
+ pub fn right_edge < ' a > ( & ' a mut self ) -> Handle < & ' a mut Node < K , V > , handle :: Edge , NodeType > {
906
912
Handle {
907
913
node : & mut * self . node ,
908
914
index : self . index + 1
909
915
}
910
916
}
911
917
}
912
918
913
- impl < K , V , NodeRef : DerefMut < Node < K , V > > > Handle < NodeRef , KV , Leaf > {
919
+ impl < K , V , NodeRef : DerefMut < Node < K , V > > > Handle < NodeRef , handle :: KV , handle :: Leaf > {
914
920
/// Removes the key/value pair at the handle's location.
915
921
///
916
922
/// # Panics (in debug build)
@@ -921,7 +927,7 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, KV, Leaf> {
921
927
}
922
928
}
923
929
924
- impl < K , V , NodeRef : DerefMut < Node < K , V > > > Handle < NodeRef , KV , Internal > {
930
+ impl < K , V , NodeRef : DerefMut < Node < K , V > > > Handle < NodeRef , handle :: KV , handle :: Internal > {
925
931
/// Steal! Stealing is roughly analogous to a binary tree rotation.
926
932
/// In this case, we're "rotating" right.
927
933
unsafe fn steal_rightward ( & mut self ) {
@@ -1004,7 +1010,8 @@ impl<K, V> Node<K, V> {
1004
1010
/// # Panics (in debug build)
1005
1011
///
1006
1012
/// Panics if the given index is out of bounds.
1007
- pub fn kv_handle ( & mut self , index : uint ) -> Handle < & mut Node < K , V > , KV , LeafOrInternal > {
1013
+ pub fn kv_handle ( & mut self , index : uint ) -> Handle < & mut Node < K , V > , handle:: KV ,
1014
+ handle:: LeafOrInternal > {
1008
1015
// Necessary for correctness, but in a private module
1009
1016
debug_assert ! ( index < self . len( ) , "kv_handle index out of bounds" ) ;
1010
1017
Handle {
0 commit comments