about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-08-10 00:44:35 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-08-10 00:44:35 +1000
commitc8ca989c0786258d2024c04fd9633056c25a8ffb (patch)
tree67ebe06e986eed920aaf51440a27e9327764cd9d /src/libstd
parent936f70bd878327d867b6f8f82061d738355a47c9 (diff)
downloadrust-c8ca989c0786258d2024c04fd9633056c25a8ffb.tar.gz
rust-c8ca989c0786258d2024c04fd9633056c25a8ffb.zip
std: add a Clone impl for HashSet.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/hashmap.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index 84cba254dcf..623d395f60d 100644
--- a/src/libstd/hashmap.rs
+++ b/src/libstd/hashmap.rs
@@ -745,6 +745,14 @@ impl<T:Hash + Eq> HashSet<T> {
 
 }
 
+impl<T:Hash + Eq + Clone> Clone for HashSet<T> {
+    fn clone(&self) -> HashSet<T> {
+        HashSet {
+            map: self.map.clone()
+        }
+    }
+}
+
 impl<K: Eq + Hash, T: Iterator<K>> FromIterator<K, T> for HashSet<K> {
     fn from_iterator(iter: &mut T) -> HashSet<K> {
         let (lower, _) = iter.size_hint();
@@ -1190,4 +1198,22 @@ mod test_set {
         let v = hs.consume().collect::<~[char]>();
         assert!(['a', 'b'] == v || ['b', 'a'] == v);
     }
+
+    #[test]
+    fn test_eq() {
+        let mut s1 = HashSet::new();
+        s1.insert(1);
+        s1.insert(2);
+        s1.insert(3);
+
+        let mut s2 = HashSet::new();
+        s2.insert(1);
+        s2.insert(2);
+
+        assert!(s1 != s2);
+
+        s2.insert(3);
+
+        assert_eq!(s1, s2);
+    }
 }