Lines Matching +full:map +full:- +full:cache
2 // Use of this source code is governed by a BSD-style license that can be
16 fn dirty(&self) -> bool; in dirty()
20 /// Represents a vector that implements the `Cacheable` trait so it can be held in a cache.
28 pub fn new(count: usize) -> VecCache<T> { in new()
36 pub fn from_vec(vec: Vec<T>) -> VecCache<T> { in from_vec()
43 pub fn get<I>(&self, index: I) -> Option<&<I as SliceIndex<[T]>>::Output> in get()
51 pub fn get_values(&self) -> &[T] { in get_values()
55 /// Mark this cache element as clean.
61 pub fn len(&self) -> usize { in len()
67 fn dirty(&self) -> bool { in dirty()
75 fn index(&self, index: usize) -> &T { in index()
81 fn index_mut(&mut self, index: usize) -> &mut T { in index_mut()
90 map: HashMap<usize, T>, field
94 pub fn new(capacity: usize) -> Self { in new()
97 map: HashMap::with_capacity(capacity), in new()
101 pub fn contains_key(&self, key: &usize) -> bool { in contains_key()
102 self.map.contains_key(key) in contains_key()
105 pub fn get(&self, index: &usize) -> Option<&T> { in get()
106 self.map.get(index) in get()
109 pub fn get_mut(&mut self, index: &usize) -> Option<&mut T> { in get_mut()
110 self.map.get_mut(index) in get_mut()
113 pub fn iter_mut(&mut self) -> IterMut<usize, T> { in iter_mut()
114 self.map.iter_mut() in iter_mut()
117 // Check if the refblock cache is full and we need to evict.
118 pub fn insert<F>(&mut self, index: usize, block: T, write_callback: F) -> io::Result<()> in insert()
120 F: FnOnce(usize, T) -> io::Result<()>, in insert()
122 if self.map.len() == self.capacity { in insert()
123 // TODO(dgreid) - smarter eviction strategy. in insert()
124 let to_evict = *self.map.iter().next().unwrap().0; in insert()
125 if let Some(evicted) = self.map.remove(&to_evict) { in insert()
131 self.map.insert(index, block); in insert()
142 fn dirty(&self) -> bool { in dirty()
149 let mut cache = CacheMap::<NumCache>::new(3); in evicts_when_full() localVariable
151 cache in evicts_when_full()
158 cache in evicts_when_full()
165 cache in evicts_when_full()
172 cache in evicts_when_full()
182 let num_items = (0..=3).filter(|k| cache.contains_key(k)).count(); in evicts_when_full()
184 assert!(cache.contains_key(&3)); in evicts_when_full()