Skip to content
Snippets Groups Projects
Commit 9524c4cb authored by Mathis "what could possibly go wrong" Randl's avatar Mathis "what could possibly go wrong" Randl
Browse files

with pre-allocated capacity

parent a0ecb060
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,7 @@ impl<K, V> FifoCache<K, V> {
assert!(tolerance > 0.0);
Self {
max_capacity,
items: VecDeque::new(),
items: VecDeque::with_capacity(max_capacity),
tolerance,
}
}
......
......@@ -72,7 +72,7 @@ where
}
fn insert(&mut self, key: K, value: V) {
if self.len() == self.max_capacity {
if self.len() >= self.max_capacity {
if let Some(tail) = self.list.remove_tail() {
self.map.remove(&tail.borrow().key);
}
......@@ -93,7 +93,7 @@ impl<K, V> LRUCache<K, V> {
assert!(tolerance > 0.0);
Self {
max_capacity,
map: HashMap::new(),
map: HashMap::with_capacity(max_capacity),
list: DoublyLinkedList::new(),
tolerance,
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment