Skip to content

Commit 3657d56

Browse files
ericktgraydon
authored andcommitted
core: add Eq impl to LinearMap.
1 parent 645bd98 commit 3657d56

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/libcore/send_map.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,25 @@ pub mod linear {
428428
option::unwrap(move value)
429429
}
430430
}
431+
432+
impl<K:Hash IterBytes Eq, V: Eq> LinearMap<K, V>: cmp::Eq {
433+
pure fn eq(&self, other: &LinearMap<K, V>) -> bool {
434+
if self.len() != other.len() { return false; }
435+
436+
for self.each |key, value| {
437+
match other.find_ref(key) {
438+
None => return false,
439+
Some(v) => if value != v { return false },
440+
}
441+
}
442+
443+
return true;
444+
}
445+
446+
pure fn ne(&self, other: &LinearMap<K, V>) -> bool {
447+
!self.eq(other)
448+
}
449+
}
431450
}
432451

433452
#[test]
@@ -538,4 +557,22 @@ pub mod test {
538557
Some(v) => assert *v == 2
539558
}
540559
}
560+
561+
#[test]
562+
pub fn test_eq() {
563+
let mut m1 = ~LinearMap();
564+
m1.insert(1, 2);
565+
m1.insert(2, 3);
566+
m1.insert(3, 4);
567+
568+
let mut m2 = ~LinearMap();
569+
m2.insert(1, 2);
570+
m2.insert(2, 3);
571+
572+
assert m1 != m2;
573+
574+
m2.insert(3, 4);
575+
576+
assert m1 == m2;
577+
}
541578
}

0 commit comments

Comments
 (0)