mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Remove HashCache.
This commit is contained in:
parent
24fe6bc4da
commit
fa05a309f3
2 changed files with 2 additions and 64 deletions
|
@ -4,58 +4,9 @@
|
|||
|
||||
use rand;
|
||||
use rand::Rng;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use std::default::Default;
|
||||
use std::hash::{BuildHasherDefault, Hash, Hasher, SipHasher};
|
||||
use std::hash::{Hash, Hasher, SipHasher};
|
||||
use std::slice::Iter;
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct HashCache<K, V>
|
||||
where K: PartialEq + Eq + Hash,
|
||||
V: Clone,
|
||||
{
|
||||
entries: HashMap<K, V, BuildHasherDefault<SipHasher>>,
|
||||
}
|
||||
|
||||
impl<K, V> HashCache<K, V>
|
||||
where K: PartialEq + Eq + Hash,
|
||||
V: Clone,
|
||||
{
|
||||
pub fn new() -> HashCache<K, V> {
|
||||
HashCache {
|
||||
entries: HashMap::with_hasher(Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, key: K, value: V) {
|
||||
self.entries.insert(key, value);
|
||||
}
|
||||
|
||||
pub fn find(&self, key: &K) -> Option<V> {
|
||||
match self.entries.get(key) {
|
||||
Some(v) => Some(v.clone()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_or_create<F>(&mut self, key: K, mut blk: F) -> V where F: FnMut() -> V {
|
||||
match self.entries.entry(key) {
|
||||
Occupied(occupied) => {
|
||||
(*occupied.get()).clone()
|
||||
}
|
||||
Vacant(vacant) => {
|
||||
(*vacant.insert(blk())).clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn evict_all(&mut self) {
|
||||
self.entries.clear();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LRUCache<K, V> {
|
||||
entries: Vec<(K, V)>,
|
||||
cache_size: usize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue