final T baseRemove(Object key) {
        int slot = findSlot(key, elements.length);
        Object object = elements[slot];
        if (object == null) {
            return null;
        } else if (object instanceof Object[]) {
            Object[] curArray = (Object[]) object;
            for (int i = 0; i < curArray.length; i++) {
                if (curArray[i].equals(key)) {
                    size--;
                    if (curArray.length <= 2) {
                        int j = i == 0 ? 1 : 0;
                        elements[slot] = curArray[j];
                    } else {
                        Object[] newArray = new Object[curArray.length - 1];
                        System.arraycopy(curArray, 0, newArray, 0, i);
                        System.arraycopy(curArray, i + 1, newArray, i, curArray.length - 1 - i);
                        elements[slot] = newArray;
                    }
                    return (T) curArray[i];
                }
            }
            return null;
        } else if (object.equals(key)) {
            size--;
            elements[slot] = null;
            return (T) object;
        } else {
            return null;
        }
    }
Calculate the capacity we should provision, given the expected size.
<br>
Our capacity must always be a power of 2, and never less than 2 or more
than MAX_CAPACITY.  We use 64-bit numbers here to avoid overflow
concerns.
server-common/src/main/java/org/apache/kafka/timeline/BaseHashTable.java