about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2014-02-24 08:11:00 -0500
committerDaniel Micay <danielmicay@gmail.com>2014-03-07 22:45:22 -0500
commit4d7d101a76deea69e9078d9ed6bb93ecca70e52a (patch)
tree3365108e59d5c6d4ee0655347ce3ed447cc7d016 /src/libcollections
parent33768c46ec980a911284d77804e5e45ead6530eb (diff)
downloadrust-4d7d101a76deea69e9078d9ed6bb93ecca70e52a.tar.gz
rust-4d7d101a76deea69e9078d9ed6bb93ecca70e52a.zip
create a sensible comparison trait hierarchy
* `Ord` inherits from `Eq`
* `TotalOrd` inherits from `TotalEq`
* `TotalOrd` inherits from `Ord`
* `TotalEq` inherits from `Eq`

This is a partial implementation of #12517.
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/btree.rs71
-rw-r--r--src/libcollections/dlist.rs2
2 files changed, 72 insertions, 1 deletions
diff --git a/src/libcollections/btree.rs b/src/libcollections/btree.rs
index 171203b00b8..6411b6bc974 100644
--- a/src/libcollections/btree.rs
+++ b/src/libcollections/btree.rs
@@ -92,6 +92,11 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for 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 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for BTree<K, V> {
     }
 }
 
+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 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for 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 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> {
     }
 }
 
+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 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for 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 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for Leaf<K, V> {
     }
 }
 
+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 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for 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 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for Branch<K, V> {
     }
 }
 
+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 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for 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 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for LeafElt<K, V> {
     }
 }
 
+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 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for 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 @@ impl<K: TotalOrd, V: TotalEq> TotalEq for BranchElt<K, V>{
     }
 }
 
+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 {
diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs
index 6c059d3f40c..9193d319310 100644
--- a/src/libcollections/dlist.rs
+++ b/src/libcollections/dlist.rs
@@ -607,7 +607,7 @@ impl<A: Eq> Eq for DList<A> {
     }
 }
 
-impl<A: Eq + Ord> Ord for DList<A> {
+impl<A: Ord> Ord for DList<A> {
     fn lt(&self, other: &DList<A>) -> bool {
         iter::order::lt(self.iter(), other.iter())
     }