use std::cast;
use std::container::Container;
-use std::hash::{Hash, sip};
+use std::hash::Hash;
use std::fmt;
use std::ptr;
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) }
}
}
}
}
+impl<K: TotalEq> TotalEq for KeyRef<K> {}
+
impl<K, V> LruEntry<K, V> {
fn new() -> LruEntry<K, V> {
LruEntry {
}
}
-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 {
}
}
-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 {
}
}
-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();
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]