From f6db0ef9464a17fa6e547e755b1b5dfa09af9499 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sun, 23 Mar 2014 22:54:42 +1100 Subject: std: remove the `equals` method from `TotalEq`. `TotalEq` is now just an assertion about the `Eq` impl of a type (i.e. `==` is a total equality if a type implements `TotalEq`) so the extra method is just confusing. Also, a new method magically appeared as a hack to allow deriving to assert that the contents of a struct/enum are also TotalEq, because the deriving infrastructure makes it very hard to do anything but create a trait method. (You didn't hear about this horrible work-around from me :(.) --- src/libcollections/btree.rs | 57 +++++++++++---------------------------------- 1 file changed, 13 insertions(+), 44 deletions(-) (limited to 'src/libcollections') diff --git a/src/libcollections/btree.rs b/src/libcollections/btree.rs index 6411b6bc974..3f53ede6027 100644 --- a/src/libcollections/btree.rs +++ b/src/libcollections/btree.rs @@ -94,17 +94,12 @@ impl Clone for BTree { impl Eq for BTree { fn eq(&self, other: &BTree) -> bool { - self.equals(other) - } -} - -impl TotalEq for BTree { - ///Testing equality on BTrees by comparing the root. - fn equals(&self, other: &BTree) -> bool { self.root.cmp(&other.root) == Equal } } +impl TotalEq for BTree {} + impl Ord for BTree { fn lt(&self, other: &BTree) -> bool { self.cmp(other) == Less @@ -204,14 +199,6 @@ impl Clone for Node { impl Eq for Node { fn eq(&self, other: &Node) -> bool { - self.equals(other) - } -} - -impl TotalEq for Node { - ///Returns whether two nodes are equal based on the keys of each element. - ///Two nodes are equal if all of their keys are the same. - fn equals(&self, other: &Node) -> bool{ match *self{ BranchNode(ref branch) => { if other.is_leaf() { @@ -232,6 +219,8 @@ impl TotalEq for Node { } } +impl TotalEq for Node {} + impl Ord for Node { fn lt(&self, other: &Node) -> bool { self.cmp(other) == Less @@ -405,16 +394,11 @@ impl Clone for Leaf { impl Eq for Leaf { fn eq(&self, other: &Leaf) -> bool { - self.equals(other) + self.elts == other.elts } } -impl TotalEq for Leaf { - ///Implementation of equals function for leaves that compares LeafElts. - fn equals(&self, other: &Leaf) -> bool { - self.elts.equals(&other.elts) - } -} +impl TotalEq for Leaf {} impl Ord for Leaf { fn lt(&self, other: &Leaf) -> bool { @@ -639,16 +623,11 @@ impl Clone for Branch { impl Eq for Branch { fn eq(&self, other: &Branch) -> bool { - self.equals(other) + self.elts == other.elts } } -impl TotalEq for Branch { - ///Equals function for Branches--compares all the elements in each branch - fn equals(&self, other: &Branch) -> bool { - self.elts.equals(&other.elts) - } -} +impl TotalEq for Branch {} impl Ord for Branch { fn lt(&self, other: &Branch) -> bool { @@ -712,16 +691,11 @@ impl Clone for LeafElt { impl Eq for LeafElt { fn eq(&self, other: &LeafElt) -> bool { - self.equals(other) + self.key == other.key && self.value == other.value } } -impl TotalEq for LeafElt { - ///TotalEq for LeafElts - fn equals(&self, other: &LeafElt) -> bool { - self.key.equals(&other.key) && self.value.equals(&other.value) - } -} +impl TotalEq for LeafElt {} impl Ord for LeafElt { fn lt(&self, other: &LeafElt) -> bool { @@ -766,16 +740,11 @@ impl Clone for BranchElt { impl Eq for BranchElt{ fn eq(&self, other: &BranchElt) -> bool { - self.equals(other) + self.key == other.key && self.value == other.value } } -impl TotalEq for BranchElt{ - ///TotalEq for BranchElts - fn equals(&self, other: &BranchElt) -> bool { - self.key.equals(&other.key)&&self.value.equals(&other.value) - } -} +impl TotalEq for BranchElt{} impl Ord for BranchElt { fn lt(&self, other: &BranchElt) -> bool { @@ -900,7 +869,7 @@ mod test_btree { fn btree_clone_test() { let b = BTree::new(1, ~"abc", 2); let b2 = b.clone(); - assert!(b.root.equals(&b2.root)) + assert!(b.root == b2.root) } //Tests the BTree's cmp() method when one node is "less than" another. -- cgit 1.4.1-3-g733a5