]> git.lizzy.rs Git - rust.git/blobdiff - src/libcollections/btree.rs
create a sensible comparison trait hierarchy
[rust.git] / src / libcollections / btree.rs
index 171203b00b806c7e35f47f5a339a20be559a9d7e..6411b6bc974356dd5fccdd7c90952e6aae68886e 100644 (file)
@@ -92,6 +92,11 @@ fn clone(&self) -> BTree<K, V> {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Eq for BTree<K, V> {
+    fn eq(&self, other: &BTree<K, V>) -> bool {
+        self.equals(other)
+    }
+}
 
 impl<K: TotalOrd, V: TotalEq> TotalEq for BTree<K, V> {
     ///Testing equality on BTrees by comparing the root.
@@ -100,6 +105,12 @@ fn equals(&self, other: &BTree<K, V>) -> bool {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Ord for BTree<K, V> {
+    fn lt(&self, other: &BTree<K, V>) -> bool {
+        self.cmp(other) == Less
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalOrd for BTree<K, V> {
     ///Returns an ordering based on the root nodes of each BTree.
     fn cmp(&self, other: &BTree<K, V>) -> Ordering {
@@ -191,6 +202,12 @@ fn clone(&self) -> Node<K, V> {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Eq for Node<K, V> {
+    fn eq(&self, other: &Node<K, V>) -> bool {
+        self.equals(other)
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> {
     ///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.
@@ -215,6 +232,12 @@ fn equals(&self, other: &Node<K, V>) -> bool{
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Ord for Node<K, V> {
+    fn lt(&self, other: &Node<K, V>) -> bool {
+        self.cmp(other) == Less
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalOrd for Node<K, V> {
     ///Implementation of TotalOrd for Nodes.
     fn cmp(&self, other: &Node<K, V>) -> Ordering {
@@ -380,6 +403,12 @@ fn clone(&self) -> Leaf<K, V> {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Eq for Leaf<K, V> {
+    fn eq(&self, other: &Leaf<K, V>) -> bool {
+        self.equals(other)
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalEq for Leaf<K, V> {
     ///Implementation of equals function for leaves that compares LeafElts.
     fn equals(&self, other: &Leaf<K, V>) -> bool {
@@ -387,6 +416,12 @@ fn equals(&self, other: &Leaf<K, V>) -> bool {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Ord for Leaf<K, V> {
+    fn lt(&self, other: &Leaf<K, V>) -> bool {
+        self.cmp(other) == Less
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalOrd for Leaf<K, V> {
     ///Returns an ordering based on the first element of each Leaf.
     fn cmp(&self, other: &Leaf<K, V>) -> Ordering {
@@ -602,6 +637,12 @@ fn clone(&self) -> Branch<K, V> {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Eq for Branch<K, V> {
+    fn eq(&self, other: &Branch<K, V>) -> bool {
+        self.equals(other)
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalEq for Branch<K, V> {
     ///Equals function for Branches--compares all the elements in each branch
     fn equals(&self, other: &Branch<K, V>) -> bool {
@@ -609,6 +650,12 @@ fn equals(&self, other: &Branch<K, V>) -> bool {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Ord for Branch<K, V> {
+    fn lt(&self, other: &Branch<K, V>) -> bool {
+        self.cmp(other) == Less
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalOrd for Branch<K, V> {
     ///Compares the first elements of two branches to determine an ordering
     fn cmp(&self, other: &Branch<K, V>) -> Ordering {
@@ -663,6 +710,12 @@ fn clone(&self) -> LeafElt<K, V> {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Eq for LeafElt<K, V> {
+    fn eq(&self, other: &LeafElt<K, V>) -> bool {
+        self.equals(other)
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalEq for LeafElt<K, V> {
     ///TotalEq for LeafElts
     fn equals(&self, other: &LeafElt<K, V>) -> bool {
@@ -670,6 +723,12 @@ fn equals(&self, other: &LeafElt<K, V>) -> bool {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Ord for LeafElt<K, V> {
+    fn lt(&self, other: &LeafElt<K, V>) -> bool {
+        self.cmp(other) == Less
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalOrd for LeafElt<K, V> {
     ///Returns an ordering based on the keys of the LeafElts.
     fn cmp(&self, other: &LeafElt<K, V>) -> Ordering {
@@ -705,6 +764,12 @@ fn clone(&self) -> BranchElt<K, V> {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Eq for BranchElt<K, V>{
+    fn eq(&self, other: &BranchElt<K, V>) -> bool {
+        self.equals(other)
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalEq for BranchElt<K, V>{
     ///TotalEq for BranchElts
     fn equals(&self, other: &BranchElt<K, V>) -> bool {
@@ -712,6 +777,12 @@ fn equals(&self, other: &BranchElt<K, V>) -> bool {
     }
 }
 
+impl<K: TotalOrd, V: TotalEq> Ord for BranchElt<K, V> {
+    fn lt(&self, other: &BranchElt<K, V>) -> bool {
+        self.cmp(other) == Less
+    }
+}
+
 impl<K: TotalOrd, V: TotalEq> TotalOrd for BranchElt<K, V> {
     ///Fulfills TotalOrd for BranchElts
     fn cmp(&self, other: &BranchElt<K, V>) -> Ordering {