MCPcopy Create free account
hub / github.com/davidgiven/luje / calculateCapacity

Method calculateCapacity

lib/java/util/HashMap.java:295–309  ·  view source on GitHub ↗

Calculates the capacity of storage required for storing given number of elements @param x number of elements @return storage size

(int x)

Source from the content-addressed store, hash-verified

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

Callers 2

HashMapMethod · 0.95
rehashMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected