diff options
Diffstat (limited to 'src/components/util/cache.rs')
-rw-r--r-- | src/components/util/cache.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/components/util/cache.rs b/src/components/util/cache.rs index dc384baf26a..3eb37145df7 100644 --- a/src/components/util/cache.rs +++ b/src/components/util/cache.rs @@ -9,6 +9,9 @@ use std::rand; use std::vec::Items; use std::vec; +#[cfg(test)] +use std::cell::Cell; + pub trait Cache<K: Eq, V: Clone> { fn insert(&mut self, key: K, value: V); fn find(&mut self, key: &K) -> Option<V>; @@ -57,8 +60,8 @@ impl<K: Clone + Eq, V: Clone> Cache<K,V> for MonoCache<K,V> { #[test] fn test_monocache() { let mut cache = MonoCache::new(10); - let one = ~"one"; - let two = ~"two"; + let one = Cell::new("one"); + let two = Cell::new("two"); cache.insert(1, one); assert!(cache.find(&1).is_some()); @@ -104,8 +107,8 @@ impl<K: Clone + Eq + Hash, V: Clone> Cache<K,V> for HashCache<K,V> { #[test] fn test_hashcache() { let mut cache = HashCache::new(); - let one = ~"one"; - let two = ~"two"; + let one = Cell::new("one"); + let two = Cell::new("two"); cache.insert(1, one); assert!(cache.find(&1).is_some()); @@ -244,10 +247,10 @@ impl<K:Clone+Eq+Hash,V:Clone> Cache<K,V> for SimpleHashCache<K,V> { #[test] fn test_lru_cache() { - let one = ~"one"; - let two = ~"two"; - let three = ~"three"; - let four = ~"four"; + let one = Cell::new("one"); + let two = Cell::new("two"); + let three = Cell::new("three"); + let four = Cell::new("four"); // Test normal insertion. let mut cache = LRUCache::new(2); // (_, _) (cache is empty) |