about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authornham <hamann.nick@gmail.com>2014-07-26 12:04:41 -0400
committernham <hamann.nick@gmail.com>2014-07-26 18:47:33 -0400
commitfadbc0b88bb39ac42aa4874e4a90df53a778ef59 (patch)
tree99e7e92d1e91d06620c0f4383c6a6d9a694955f1 /src
parent3f1c37e96da571e6eb8137aad1b5d65ea3f89a0b (diff)
Manually implement Hash for SmallIntMap
Diffstat (limited to 'src')
-rw-r--r--src/libcollections/smallintmap.rs32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs
index 56fb7e3632e..c6c55b55e33 100644
--- a/src/libcollections/smallintmap.rs
+++ b/src/libcollections/smallintmap.rs
@@ -24,6 +24,8 @@ use core::mem::replace;
 use {Collection, Mutable, Map, MutableMap, MutableSeq};
 use {vec, slice};
 use vec::Vec;
+use hash;
+use hash::Hash;
 
 /// A map optimized for small integer keys.
 ///
@@ -58,7 +60,7 @@ use vec::Vec;
 /// months.clear();
 /// assert!(months.is_empty());
 /// ```
-#[deriving(Hash, PartialEq, Eq)]
+#[deriving(PartialEq, Eq)]
 pub struct SmallIntMap<T> {
     v: Vec<Option<T>>,
 }
@@ -167,6 +169,12 @@ impl<V:Clone> Clone for SmallIntMap<V> {
     }
 }
 
+impl <S: hash::Writer, T: Hash<S>> Hash<S> for SmallIntMap<T> {
+    fn hash(&self, state: &mut S) {
+        self.v.hash(state)
+    }
+}
+
 impl<V> SmallIntMap<V> {
     /// Create an empty SmallIntMap.
     ///
@@ -478,8 +486,8 @@ pub type Values<'a, T> =
 #[cfg(test)]
 mod test_map {
     use std::prelude::*;
-    use std::hash;
     use vec::Vec;
+    use hash;
 
     use {Map, MutableMap, Mutable, MutableSeq};
     use super::SmallIntMap;
@@ -764,19 +772,19 @@ mod test_map {
 
     #[test]
     fn test_hash() {
-      let mut x = SmallIntMap::new();
-      let mut y = SmallIntMap::new();
+        let mut x = SmallIntMap::new();
+        let mut y = SmallIntMap::new();
 
-      assert!(hash::hash(&x) == hash::hash(&y));
-      x.insert(1, 'a');
-      x.insert(2, 'b');
-      x.insert(3, 'c');
+        assert!(hash::hash(&x) == hash::hash(&y));
+        x.insert(1, 'a');
+        x.insert(2, 'b');
+        x.insert(3, 'c');
 
-      y.insert(3, 'c');
-      y.insert(2, 'b');
-      y.insert(1, 'a');
+        y.insert(3, 'c');
+        y.insert(2, 'b');
+        y.insert(1, 'a');
 
-      assert!(hash::hash(&x) == hash::hash(&y));
+        assert!(hash::hash(&x) == hash::hash(&y));
     }
 
     #[test]