@@ -34,9 +34,9 @@ pub enum InsertionResult<K, V> {
3434/// Represents the result of a search for a key in a single node
3535pub enum SearchResult < NodeRef > {
3636 /// The element was found at the given index
37- Found ( Handle < NodeRef , KV , LeafOrInternal > ) ,
37+ Found ( Handle < NodeRef , handle :: KV , handle :: LeafOrInternal > ) ,
3838 /// 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 > ) ,
4040}
4141
4242/// 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> {
494494 index : uint
495495}
496496
497- pub enum KV { }
498- pub enum Edge { }
497+ pub mod handle {
498+ // Handle types.
499+ pub enum KV { }
500+ pub enum Edge { }
499501
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+ }
503507
504508impl < K : Ord , V > Node < K , V > {
505509 /// 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> {
625629 }
626630}
627631
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 > {
629633 /// Turns the handle into a reference to the edge it points at. This is necessary because the
630634 /// returned pointer has a larger lifetime than what would be returned by `edge` or `edge_mut`,
631635 /// 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> {
636640 }
637641}
638642
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 > {
640644 /// Turns the handle into a mutable reference to the edge it points at. This is necessary
641645 /// because the returned pointer has a larger lifetime than what would be returned by
642646 /// `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> {
647651 }
648652}
649653
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 > {
651655 // This doesn't exist because there are no uses for it,
652656 // but is fine to add, analagous to edge_mut.
653657 //
@@ -657,11 +661,11 @@ impl<K, V, NodeRef: Deref<Node<K, V>>> Handle<NodeRef, Edge, Internal> {
657661}
658662
659663pub 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 > )
662666}
663667
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 > {
665669 /// Figure out whether this handle is pointing to something in a leaf node or to something in
666670 /// an internal node, clarifying the type according to the result.
667671 pub fn force ( self ) -> ForceResult < NodeRef , Type > {
@@ -679,7 +683,7 @@ impl<K, V, NodeRef: Deref<Node<K, V>>, Type> Handle<NodeRef, Type, LeafOrInterna
679683 }
680684}
681685
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 > {
683687 /// Tries to insert this key-value pair at the given index in this leaf node
684688 /// If the node is full, we have to split it.
685689 ///
@@ -711,7 +715,7 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, Edge, Leaf> {
711715 }
712716}
713717
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 > {
715719 /// Returns a mutable reference to the edge pointed-to by this handle. This should not be
716720 /// confused with `node`, which references the parent node of what is returned here.
717721 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> {
794798 }
795799}
796800
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 > {
798802 /// Gets the handle pointing to the key/value pair just to the left of the pointed-to edge.
799803 /// This is unsafe because the handle might point to the first edge in the node, which has no
800804 /// 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 > {
802806 Handle {
803807 node : & mut * self . node ,
804808 index : self . index - 1
@@ -808,15 +812,15 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, Edge, NodeTy
808812 /// Gets the handle pointing to the key/value pair just to the right of the pointed-to edge.
809813 /// This is unsafe because the handle might point to the last edge in the node, which has no
810814 /// 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 > {
812816 Handle {
813817 node : & mut * self . node ,
814818 index : self . index
815819 }
816820 }
817821}
818822
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 > {
820824 /// Turns the handle into references to the key and value it points at. This is necessary
821825 /// because the returned pointers have larger lifetimes than what would be returned by `key`
822826 /// or `val`.
@@ -831,7 +835,7 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a Node<K, V>, KV, NodeType> {
831835 }
832836}
833837
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 > {
835839 /// Turns the handle into mutable references to the key and value it points at. This is
836840 /// necessary because the returned pointers have larger lifetimes than what would be returned
837841 /// 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> {
848852 /// Convert this handle into one pointing at the edge immediately to the left of the key/value
849853 /// pair pointed-to by this handle. This is useful because it returns a reference with larger
850854 /// 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 > {
852856 Handle {
853857 node : & mut * self . node ,
854858 index : self . index
855859 }
856860 }
857861}
858862
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 > {
860865 // These are fine to include, but are currently unneeded.
861866 //
862867 // /// 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
874879 // }
875880}
876881
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 > {
878884 /// Returns a mutable reference to the key pointed-to by this handle. This doesn't return a
879885 /// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
880886 /// handle.
@@ -890,10 +896,10 @@ impl<'a, K: 'a, V: 'a, NodeRef: DerefMut<Node<K, V>> + 'a, NodeType> Handle<Node
890896 }
891897}
892898
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 > {
894900 /// Gets the handle pointing to the edge immediately to the left of the key/value pair pointed
895901 /// 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 > {
897903 Handle {
898904 node : & mut * self . node ,
899905 index : self . index
@@ -902,15 +908,15 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, KV, NodeType
902908
903909 /// Gets the handle pointing to the edge immediately to the right of the key/value pair pointed
904910 /// 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 > {
906912 Handle {
907913 node : & mut * self . node ,
908914 index : self . index + 1
909915 }
910916 }
911917}
912918
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 > {
914920 /// Removes the key/value pair at the handle's location.
915921 ///
916922 /// # Panics (in debug build)
@@ -921,7 +927,7 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, KV, Leaf> {
921927 }
922928}
923929
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 > {
925931 /// Steal! Stealing is roughly analogous to a binary tree rotation.
926932 /// In this case, we're "rotating" right.
927933 unsafe fn steal_rightward ( & mut self ) {
@@ -1004,7 +1010,8 @@ impl<K, V> Node<K, V> {
10041010 /// # Panics (in debug build)
10051011 ///
10061012 /// 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 > {
10081015 // Necessary for correctness, but in a private module
10091016 debug_assert ! ( index < self . len( ) , "kv_handle index out of bounds" ) ;
10101017 Handle {
0 commit comments