Calculates the capacity of storage required for storing given number of elements @param x number of elements @return storage size
(int x)
| 293 | * @return storage size |
| 294 | */ |
| 295 | private static final int calculateCapacity(int x) { |
| 296 | if(x >= 1 << 30){ |
| 297 | return 1 << 30; |
| 298 | } |
| 299 | if(x == 0){ |
| 300 | return 16; |
| 301 | } |
| 302 | x = x -1; |
| 303 | x |= x >> 1; |
| 304 | x |= x >> 2; |
| 305 | x |= x >> 4; |
| 306 | x |= x >> 8; |
| 307 | x |= x >> 16; |
| 308 | return x + 1; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Constructs a new {@code HashMap} instance with the specified capacity and |