leventov / Koloboke

Java Collections till the last breadcrumb of memory and performance
https://koloboke.com/
1.01k stars 139 forks source link

Field removedSlots cleared too early in rehash #51

Open niemisto opened 8 years ago

niemisto commented 8 years ago

I noticed the following problem in rehash implementation, at least in MutableObjQHashSetSO.

    void rehash(int newCapacity) {
        int mc = modCount();
        Object[] keys = set;
        initForRehash(newCapacity);
        mc++; // modCount is incremented in initForRehash()
        Object[] newKeys = set;
        int capacity = newKeys.length;
        if (noRemoved()) {
            ...

The method initForRehash calls internalInit that calls initSlotCounts that sets removedSlots to zero. Therefore the test noRemoved() always succeeds even when the hash set contains REMOVED entries. This bug appears in koloboke-impl-jdk8 1.0.0 I downloaded from Maven central.