]> git.lizzy.rs Git - rust.git/blobdiff - src/libcollections/lru_cache.rs
use TotalEq for HashMap
[rust.git] / src / libcollections / lru_cache.rs
index 68bc5f1b6c4ff60c7818b604b1ebfd475d29e4f1..e328b41cc0fff83cc06b093fa2caf7fe0e711141 100644 (file)
@@ -39,7 +39,7 @@
 
 use std::cast;
 use std::container::Container;
-use std::hash::{Hash, sip};
+use std::hash::Hash;
 use std::fmt;
 use std::ptr;
 
@@ -62,9 +62,9 @@ pub struct LruCache<K, V> {
     priv tail: *mut LruEntry<K, V>,
 }
 
-impl<K: Hash> Hash for KeyRef<K> {
-    fn hash(&self, s: &mut sip::SipState) {
-        unsafe {(*self.k).hash(s)}
+impl<S, K: Hash<S>> Hash<S> for KeyRef<K> {
+    fn hash(&self, state: &mut S) {
+        unsafe { (*self.k).hash(state) }
     }
 }
 
@@ -74,6 +74,8 @@ fn eq(&self, other: &KeyRef<K>) -> bool {
     }
 }
 
+impl<K: TotalEq> TotalEq for KeyRef<K> {}
+
 impl<K, V> LruEntry<K, V> {
     fn new() -> LruEntry<K, V> {
         LruEntry {
@@ -94,7 +96,7 @@ fn with_key_value(k: K, v: V) -> LruEntry<K, V> {
     }
 }
 
-impl<K: Hash + Eq, V> LruCache<K, V> {
+impl<K: Hash + TotalEq, V> LruCache<K, V> {
     /// Create an LRU Cache that holds at most `capacity` items.
     pub fn new(capacity: uint) -> LruCache<K, V> {
         let cache = LruCache {
@@ -218,7 +220,7 @@ fn attach(&mut self, node: *mut LruEntry<K, V>) {
     }
 }
 
-impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for LruCache<A, B> {
+impl<A: fmt::Show + Hash + TotalEq, B: fmt::Show> fmt::Show for LruCache<A, B> {
     /// Return a string that lists the key-value pairs from most-recently
     /// used to least-recently used.
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -247,14 +249,14 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-impl<K: Hash + Eq, V> Container for LruCache<K, V> {
+impl<K: Hash + TotalEq, V> Container for LruCache<K, V> {
     /// Return the number of key-value pairs in the cache.
     fn len(&self) -> uint {
         self.map.len()
     }
 }
 
-impl<K: Hash + Eq, V> Mutable for LruCache<K, V> {
+impl<K: Hash + TotalEq, V> Mutable for LruCache<K, V> {
     /// Clear the cache of all key-value pairs.
     fn clear(&mut self) {
         self.map.clear();
@@ -277,7 +279,7 @@ mod tests {
 
     fn assert_opt_eq<V: Eq>(opt: Option<&V>, v: V) {
         assert!(opt.is_some());
-        assert_eq!(opt.unwrap(), &v);
+        assert!(opt.unwrap() == &v);
     }
 
     #[test]