@VisibleForTesting fun chooseTableSize(setSize: Int): Int { if (setSize == 1) { return 2 } var tableSize = Integer.highestOneBit(setSize - 1) shl 1 while (tableSize * DESIRED_LOAD_FACTOR < setSize) { tableSize = tableSize shl 1 } return tableSize }
Returns an array size suitable for the backing array of a hash table that uses open addressing with linear probing in its implementation . The returned size is the smallest power of two that can hold setSize elements with the desired load factor .