Implement PartialOrd for SmallIntMap

This commit is contained in:
nham 2014-07-28 00:00:29 -04:00
parent 16acc10bf9
commit 220f8f6dcb

View File

@ -373,6 +373,13 @@ pub fn update_with_key(&mut self,
}
}
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, "{{"));
@ -770,6 +777,38 @@ fn test_eq() {
assert!(a == b);
}
#[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();