wvwwvwwv / scalable-concurrent-containers

High performance containers and utilities for concurrent and asynchronous programming
Apache License 2.0
285 stars 14 forks source link

Premature evicting entries in HashCache #130

Closed feymartynov closed 4 months ago

feymartynov commented 4 months ago

The following example often panics proving that HashCache may evict entries even when capacity is not yet fully occupated.

const CAPACITY: usize = 64;
let hc = scc::HashCache::with_capacity(CAPACITY, CAPACITY);

for i in 0..CAPACITY {
    let k = format!("key{i}");

    match hc.put(k, i).unwrap() {
        None => (),
        Some((k, _)) => panic!("Evicted {k}"),
    }
}

Is this a bug or normal behavior? If it's normal, I think it should be documented.

wvwwvwwv commented 4 months ago

Hi!

It’s unfortunately intended. HashCache is basically the same with HashMap except that it evicts an entry if the bucket is full instead of allocating backup linked list storage, even when there are free slots in other buckets. I’ll add this to the document!

wvwwvwwv commented 4 months ago

Updated the doc!