private int ensureIndex(Object key) {
        int hash = key.hashCode();
        int index = -1;
        int firstDeleted = -1;
        if (keys != null) {
            int fraction = hash * A;
            index = fraction >>> (32 - power);
            Object test = keys[index];
            if (test != null) {
                int N = 1 << power;
                if (test == key
                    || (values[N + index] == hash && test.equals(key)))
                {
                    return index;
                }
                if (test == DELETED) {
                    firstDeleted = index;
                }

                // Search in table after first failed attempt
                int mask = N - 1;
                int step = tableLookupStep(fraction, mask, power);
                int n = 0;
                for (;;) {
                    if (check) {
                        if (n >= occupiedCount) Kit.codeBug();
                        ++n;
                    }
                    index = (index + step) & mask;
                    test = keys[index];
                    if (test == null) {
                        break;
                    }
                    if (test == key
                        || (values[N + index] == hash && test.equals(key)))
                    {
                        return index;
                    }
                    if (test == DELETED && firstDeleted < 0) {
                        firstDeleted = index;
                    }
                }
            }
        }
        // Inserting of new key
        if (check && keys != null && keys[index] != null)
            Kit.codeBug();
        if (firstDeleted >= 0) {
            index = firstDeleted;
        }
        else {
            // Need to consume empty entry: check occupation level
            if (keys == null || occupiedCount * 4 >= (1 << power) * 3) {
                // Too litle unused entries: rehash
                rehashTable();
                return insertNewKey(key, hash);
            }
            ++occupiedCount;
        }
        keys[index] = key;
        values[(1 << power) + index] = hash;
        ++keyCount;
        return index;
    }
private int ensureIndex ( Object key ) { int hash = key . hashCode ( ) ; int index = - 1 ; int firstDeleted = - 1 ; if ( keys != null ) { int fraction = hash * A ; index = fraction > > > ( 32 - power ) ; Object test = keys [ index ] ; if ( test != null ) { int N = 1 << power ; if ( test == key || ( values [ N + index ] == hash && test . equals ( key ) ) ) { return index ; } if ( test == DELETED ) { firstDeleted = index ; } int mask = N - 1 ; int step = tableLookupStep ( fraction , mask , power ) ; int n = 0 ; for ( ; ; ) { if ( check ) { if ( n >= occupiedCount ) Kit . codeBug ( ) ; ++ n ; } index = ( index + step ) & mask ; test = keys [ index ] ; if ( test == null ) { break ; } if ( test == key || ( values [ N + index ] == hash && test . equals ( key ) ) ) { return index ; } if ( test == DELETED && firstDeleted < 0 ) { firstDeleted = index ; } } } } if ( check && keys != null && keys [ index ] != null ) Kit . codeBug ( ) ; if ( firstDeleted >= 0 ) { index = firstDeleted ; } else { if ( keys == null || occupiedCount * 4 >= ( 1 << power ) * 3 ) { rehashTable ( ) ; return insertNewKey ( key , hash ) ; } ++ occupiedCount ; } keys [ index ] = key ; values [ ( 1 << power ) + index ] = hash ; ++ keyCount ; return index ; }
Ensure key index creating one if necessary