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. Do not call this method with setSize < 2.
(int setSize)
| 215 | */ |
| 216 | |
| 217 | @VisibleForTesting |
| 218 | static int chooseTableSize(int setSize) { |
| 219 | // Correct the size for open addressing to match desired load factor. |
| 220 | if (setSize < CUTOFF) { |
| 221 | // Round up to the next highest power of 2. |
| 222 | int tableSize = Integer.highestOneBit(setSize - 1) << 1; |
| 223 | while (tableSize * DESIRED_LOAD_FACTOR < setSize) { |
| 224 | tableSize <<= 1; |
| 225 | } |
| 226 | return tableSize; |
| 227 | } |
| 228 | |
| 229 | // The table can't be completely full or we'll get infinite reprobes |
| 230 | checkArgument(setSize < MAX_TABLE_SIZE, "collection too large"); |
| 231 | return MAX_TABLE_SIZE; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Returns an immutable set containing each of {@code elements}, minus duplicates, in the order |
no test coverage detected