Skip to content

Commit c8ca989

Browse files
committed
std: add a Clone impl for HashSet.
1 parent 936f70b commit c8ca989

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/libstd/hashmap.rs

+26
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,14 @@ impl<T:Hash + Eq> HashSet<T> {
745745

746746
}
747747

748+
impl<T:Hash + Eq + Clone> Clone for HashSet<T> {
749+
fn clone(&self) -> HashSet<T> {
750+
HashSet {
751+
map: self.map.clone()
752+
}
753+
}
754+
}
755+
748756
impl<K: Eq + Hash, T: Iterator<K>> FromIterator<K, T> for HashSet<K> {
749757
fn from_iterator(iter: &mut T) -> HashSet<K> {
750758
let (lower, _) = iter.size_hint();
@@ -1190,4 +1198,22 @@ mod test_set {
11901198
let v = hs.consume().collect::<~[char]>();
11911199
assert!(['a', 'b'] == v || ['b', 'a'] == v);
11921200
}
1201+
1202+
#[test]
1203+
fn test_eq() {
1204+
let mut s1 = HashSet::new();
1205+
s1.insert(1);
1206+
s1.insert(2);
1207+
s1.insert(3);
1208+
1209+
let mut s2 = HashSet::new();
1210+
s2.insert(1);
1211+
s2.insert(2);
1212+
1213+
assert!(s1 != s2);
1214+
1215+
s2.insert(3);
1216+
1217+
assert_eq!(s1, s2);
1218+
}
11931219
}

0 commit comments

Comments
 (0)