tools/lru_cache: make minimum capacity 1

Setting this to 0 is not just useless, but breaks the logic horribly
enough to cause random segfaults - better forbid this, to avoid someone
else having to debug it again ;)

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2021-06-07 17:35:30 +02:00 committed by Wolfgang Bumiller
parent da78b90f9c
commit 4121628d99

View File

@ -106,6 +106,7 @@ unsafe impl<K: Send, V: Send> Send for LruCache<K, V> {}
impl<K: std::cmp::Eq + std::hash::Hash + Copy, V> LruCache<K, V> {
/// Create LRU cache instance which holds up to `capacity` nodes at once.
pub fn new(capacity: usize) -> Self {
let capacity = capacity.min(1);
Self {
map: HashMap::with_capacity(capacity),
list: LinkedList::new(),