Calculates the capacity of storage required for storing given number of elements @param x number of elements @return storage size
(int x)
| 280 | * @return storage size |
| 281 | */ |
| 282 | private static final int calculateCapacity(int x) { |
| 283 | if(x >= 1 << 30){ |
| 284 | return 1 << 30; |
| 285 | } |
| 286 | if(x == 0){ |
| 287 | return 16; |
| 288 | } |
| 289 | x = x -1; |
| 290 | x |= x >> 1; |
| 291 | x |= x >> 2; |
| 292 | x |= x >> 4; |
| 293 | x |= x >> 8; |
| 294 | x |= x >> 16; |
| 295 | return x + 1; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Constructs a new {@code HashMap} instance with the specified capacity and |