diff options
| author | nham <hamann.nick@gmail.com> | 2014-07-28 00:00:29 -0400 |
|---|---|---|
| committer | nham <hamann.nick@gmail.com> | 2014-07-28 00:00:29 -0400 |
| commit | 220f8f6dcb37fd4db4d489337890a4d900e50503 (patch) | |
| tree | 56a8ac114b289d819022396878860572ad9a844a | |
| parent | 16acc10bf9f0318d1d6e310a1fd23dd242811d10 (diff) | |
| download | rust-220f8f6dcb37fd4db4d489337890a4d900e50503.tar.gz rust-220f8f6dcb37fd4db4d489337890a4d900e50503.zip | |
Implement PartialOrd for SmallIntMap
| -rw-r--r-- | src/libcollections/smallintmap.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index a60f80b9aef..5acabecb6ee 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -373,6 +373,13 @@ impl<V:Clone> SmallIntMap<V> { } } +impl<V: PartialOrd> PartialOrd for SmallIntMap<V> { + #[inline] + fn partial_cmp(&self, other: &SmallIntMap<V>) -> Option<Ordering> { + iter::order::partial_cmp(self.iter(), other.iter()) + } +} + impl<V: fmt::Show> fmt::Show for SmallIntMap<V> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); @@ -771,6 +778,38 @@ mod test_map { } #[test] + fn test_lt() { + let mut a = SmallIntMap::new(); + let mut b = SmallIntMap::new(); + + assert!(!(a < b) && !(b < a)); + assert!(b.insert(2u, 5i)); + assert!(a < b); + assert!(a.insert(2, 7)); + assert!(!(a < b) && b < a); + assert!(b.insert(1, 0)); + assert!(b < a); + assert!(a.insert(0, 6)); + assert!(a < b); + assert!(a.insert(6, 2)); + assert!(a < b && !(b < a)); + } + + #[test] + fn test_ord() { + let mut a = SmallIntMap::new(); + let mut b = SmallIntMap::new(); + + assert!(a <= b && a >= b); + assert!(a.insert(1u, 1i)); + assert!(a > b && a >= b); + assert!(b < a && b <= a); + assert!(b.insert(2, 2)); + assert!(b > a && b >= a); + assert!(a < b && a <= b); + } + + #[test] fn test_hash() { let mut x = SmallIntMap::new(); let mut y = SmallIntMap::new(); |
