boyter / scc

Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go
MIT License
6.57k stars 262 forks source link

Premature entry evicting in HashCache #436

Closed feymartynov closed 6 months ago

feymartynov commented 6 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.

boyter commented 6 months ago

Are you sure you are in the right project?

feymartynov commented 6 months ago

Sorry, that's wrong one :)