Skip to content

Commit 0687e2c

Browse files
committed
---
yaml --- r: 124967 b: refs/heads/auto c: 366c66e h: refs/heads/master i: 124965: 7e7193c 124963: 3063892 124959: b2af413 v: v3
1 parent 9a10f36 commit 0687e2c

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 9e83d29f30046292f43e982893517f9aee47fa48
16+
refs/heads/auto: 366c66e171b94ef78ce7b8daf2530dbdc30eadb9
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libcollections/trie.rs

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ pub struct TrieMap<T> {
4141
length: uint
4242
}
4343

44+
impl<T: PartialEq> PartialEq for TrieMap<T> {
45+
fn eq(&self, other: &TrieMap<T>) -> bool {
46+
self.len() == other.len() &&
47+
self.iter().zip(other.iter()).all(|(a, b)| a == b)
48+
}
49+
}
50+
51+
impl<T: Eq> Eq for TrieMap<T> {}
52+
4453
impl<T> Collection for TrieMap<T> {
4554
/// Return the number of elements in the map
4655
#[inline]
@@ -302,7 +311,7 @@ impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
302311
}
303312

304313
#[allow(missing_doc)]
305-
#[deriving(Hash)]
314+
#[deriving(Hash, PartialEq, Eq)]
306315
pub struct TrieSet {
307316
map: TrieMap<()>
308317
}
@@ -671,6 +680,7 @@ mod test_map {
671680
use std::prelude::*;
672681
use std::iter::range_step;
673682
use std::uint;
683+
use std::hash;
674684

675685
use {MutableMap, Map};
676686
use super::{TrieMap, TrieNode, Internal, External, Nothing};
@@ -943,6 +953,41 @@ mod test_map {
943953
assert!(m_lower.iter().all(|(_, &x)| x == 0));
944954
assert!(m_upper.iter().all(|(_, &x)| x == 0));
945955
}
956+
957+
#[test]
958+
fn test_eq() {
959+
let mut a = TrieMap::new();
960+
let mut b = TrieMap::new();
961+
962+
assert!(a == b);
963+
assert!(a.insert(0, 5i));
964+
assert!(a != b);
965+
assert!(b.insert(0, 4i));
966+
assert!(a != b);
967+
assert!(a.insert(5, 19));
968+
assert!(a != b);
969+
assert!(!b.insert(0, 5));
970+
assert!(a != b);
971+
assert!(b.insert(5, 19));
972+
assert!(a == b);
973+
}
974+
975+
#[test]
976+
fn test_hash() {
977+
let mut x = TrieMap::new();
978+
let mut y = TrieMap::new();
979+
980+
assert!(hash::hash(&x) == hash::hash(&y));
981+
x.insert(1, 'a');
982+
x.insert(2, 'b');
983+
x.insert(3, 'c');
984+
985+
y.insert(3, 'c');
986+
y.insert(2, 'b');
987+
y.insert(1, 'a');
988+
989+
assert!(hash::hash(&x) == hash::hash(&y));
990+
}
946991
}
947992

948993
#[cfg(test)]
@@ -1059,7 +1104,6 @@ mod bench_map {
10591104
mod test_set {
10601105
use std::prelude::*;
10611106
use std::uint;
1062-
use std::hash;
10631107

10641108
use {MutableSet, Set};
10651109
use super::TrieSet;
@@ -1093,20 +1137,4 @@ mod test_set {
10931137
assert!(set.contains(x));
10941138
}
10951139
}
1096-
1097-
#[test]
1098-
fn test_hash() {
1099-
let mut x = TrieSet::new();
1100-
let mut y = TrieSet::new();
1101-
1102-
x.insert(1);
1103-
x.insert(2);
1104-
x.insert(3);
1105-
1106-
y.insert(3);
1107-
y.insert(2);
1108-
y.insert(1);
1109-
1110-
assert!(hash::hash(&x) == hash::hash(&y));
1111-
}
11121140
}

0 commit comments

Comments
 (0)