@@ -94,17 +94,12 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for BTree<K, V> {
94
94
95
95
impl < K : TotalOrd , V : TotalEq > Eq for BTree < K , V > {
96
96
fn eq ( & self , other : & BTree < K , V > ) -> bool {
97
- self . equals ( other)
98
- }
99
- }
100
-
101
- impl < K : TotalOrd , V : TotalEq > TotalEq for BTree < K , V > {
102
- ///Testing equality on BTrees by comparing the root.
103
- fn equals ( & self , other : & BTree < K , V > ) -> bool {
104
97
self . root . cmp ( & other. root ) == Equal
105
98
}
106
99
}
107
100
101
+ impl < K : TotalOrd , V : TotalEq > TotalEq for BTree < K , V > { }
102
+
108
103
impl < K : TotalOrd , V : TotalEq > Ord for BTree < K , V > {
109
104
fn lt ( & self , other : & BTree < K , V > ) -> bool {
110
105
self . cmp ( other) == Less
@@ -204,14 +199,6 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Node<K, V> {
204
199
205
200
impl < K : TotalOrd , V : TotalEq > Eq for Node < K , V > {
206
201
fn eq ( & self , other : & Node < K , V > ) -> bool {
207
- self . equals ( other)
208
- }
209
- }
210
-
211
- impl < K : TotalOrd , V : TotalEq > TotalEq for Node < K , V > {
212
- ///Returns whether two nodes are equal based on the keys of each element.
213
- ///Two nodes are equal if all of their keys are the same.
214
- fn equals ( & self , other : & Node < K , V > ) -> bool {
215
202
match * self {
216
203
BranchNode ( ref branch) => {
217
204
if other. is_leaf ( ) {
@@ -232,6 +219,8 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> {
232
219
}
233
220
}
234
221
222
+ impl < K : TotalOrd , V : TotalEq > TotalEq for Node < K , V > { }
223
+
235
224
impl < K : TotalOrd , V : TotalEq > Ord for Node < K , V > {
236
225
fn lt ( & self , other : & Node < K , V > ) -> bool {
237
226
self . cmp ( other) == Less
@@ -405,16 +394,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Leaf<K, V> {
405
394
406
395
impl < K : TotalOrd , V : TotalEq > Eq for Leaf < K , V > {
407
396
fn eq ( & self , other : & Leaf < K , V > ) -> bool {
408
- self . equals ( other)
397
+ self . elts == other. elts
409
398
}
410
399
}
411
400
412
- impl < K : TotalOrd , V : TotalEq > TotalEq for Leaf < K , V > {
413
- ///Implementation of equals function for leaves that compares LeafElts.
414
- fn equals ( & self , other : & Leaf < K , V > ) -> bool {
415
- self . elts . equals ( & other. elts )
416
- }
417
- }
401
+ impl < K : TotalOrd , V : TotalEq > TotalEq for Leaf < K , V > { }
418
402
419
403
impl < K : TotalOrd , V : TotalEq > Ord for Leaf < K , V > {
420
404
fn lt ( & self , other : & Leaf < K , V > ) -> bool {
@@ -639,16 +623,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Branch<K, V> {
639
623
640
624
impl < K : TotalOrd , V : TotalEq > Eq for Branch < K , V > {
641
625
fn eq ( & self , other : & Branch < K , V > ) -> bool {
642
- self . equals ( other)
626
+ self . elts == other. elts
643
627
}
644
628
}
645
629
646
- impl < K : TotalOrd , V : TotalEq > TotalEq for Branch < K , V > {
647
- ///Equals function for Branches--compares all the elements in each branch
648
- fn equals ( & self , other : & Branch < K , V > ) -> bool {
649
- self . elts . equals ( & other. elts )
650
- }
651
- }
630
+ impl < K : TotalOrd , V : TotalEq > TotalEq for Branch < K , V > { }
652
631
653
632
impl < K : TotalOrd , V : TotalEq > Ord for Branch < K , V > {
654
633
fn lt ( & self , other : & Branch < K , V > ) -> bool {
@@ -712,16 +691,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for LeafElt<K, V> {
712
691
713
692
impl < K : TotalOrd , V : TotalEq > Eq for LeafElt < K , V > {
714
693
fn eq ( & self , other : & LeafElt < K , V > ) -> bool {
715
- self . equals ( other)
694
+ self . key == other. key && self . value == other . value
716
695
}
717
696
}
718
697
719
- impl < K : TotalOrd , V : TotalEq > TotalEq for LeafElt < K , V > {
720
- ///TotalEq for LeafElts
721
- fn equals ( & self , other : & LeafElt < K , V > ) -> bool {
722
- self . key . equals ( & other. key ) && self . value . equals ( & other. value )
723
- }
724
- }
698
+ impl < K : TotalOrd , V : TotalEq > TotalEq for LeafElt < K , V > { }
725
699
726
700
impl < K : TotalOrd , V : TotalEq > Ord for LeafElt < K , V > {
727
701
fn lt ( & self , other : & LeafElt < K , V > ) -> bool {
@@ -766,16 +740,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for BranchElt<K, V> {
766
740
767
741
impl < K : TotalOrd , V : TotalEq > Eq for BranchElt < K , V > {
768
742
fn eq ( & self , other : & BranchElt < K , V > ) -> bool {
769
- self . equals ( other)
743
+ self . key == other. key && self . value == other . value
770
744
}
771
745
}
772
746
773
- impl < K : TotalOrd , V : TotalEq > TotalEq for BranchElt < K , V > {
774
- ///TotalEq for BranchElts
775
- fn equals ( & self , other : & BranchElt < K , V > ) -> bool {
776
- self . key . equals ( & other. key ) &&self . value . equals ( & other. value )
777
- }
778
- }
747
+ impl < K : TotalOrd , V : TotalEq > TotalEq for BranchElt < K , V > { }
779
748
780
749
impl < K : TotalOrd , V : TotalEq > Ord for BranchElt < K , V > {
781
750
fn lt ( & self , other : & BranchElt < K , V > ) -> bool {
@@ -900,7 +869,7 @@ mod test_btree {
900
869
fn btree_clone_test() {
901
870
let b = BTree::new(1, ~" abc", 2);
902
871
let b2 = b.clone();
903
- assert!(b.root.equals(& b2.root) )
872
+ assert!(b.root == b2.root)
904
873
}
905
874
906
875
//Tests the BTree's cmp() method when one node is " less than" another.
0 commit comments