Skip to content

Commit 220f8f6

Browse files
committed
Implement PartialOrd for SmallIntMap
1 parent 16acc10 commit 220f8f6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/libcollections/smallintmap.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ impl<V:Clone> SmallIntMap<V> {
373373
}
374374
}
375375

376+
impl<V: PartialOrd> PartialOrd for SmallIntMap<V> {
377+
#[inline]
378+
fn partial_cmp(&self, other: &SmallIntMap<V>) -> Option<Ordering> {
379+
iter::order::partial_cmp(self.iter(), other.iter())
380+
}
381+
}
382+
376383
impl<V: fmt::Show> fmt::Show for SmallIntMap<V> {
377384
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
378385
try!(write!(f, "{{"));
@@ -770,6 +777,38 @@ mod test_map {
770777
assert!(a == b);
771778
}
772779

780+
#[test]
781+
fn test_lt() {
782+
let mut a = SmallIntMap::new();
783+
let mut b = SmallIntMap::new();
784+
785+
assert!(!(a < b) && !(b < a));
786+
assert!(b.insert(2u, 5i));
787+
assert!(a < b);
788+
assert!(a.insert(2, 7));
789+
assert!(!(a < b) && b < a);
790+
assert!(b.insert(1, 0));
791+
assert!(b < a);
792+
assert!(a.insert(0, 6));
793+
assert!(a < b);
794+
assert!(a.insert(6, 2));
795+
assert!(a < b && !(b < a));
796+
}
797+
798+
#[test]
799+
fn test_ord() {
800+
let mut a = SmallIntMap::new();
801+
let mut b = SmallIntMap::new();
802+
803+
assert!(a <= b && a >= b);
804+
assert!(a.insert(1u, 1i));
805+
assert!(a > b && a >= b);
806+
assert!(b < a && b <= a);
807+
assert!(b.insert(2, 2));
808+
assert!(b > a && b >= a);
809+
assert!(a < b && a <= b);
810+
}
811+
773812
#[test]
774813
fn test_hash() {
775814
let mut x = SmallIntMap::new();

0 commit comments

Comments
 (0)