@Test public void shouldReturnsRequiredTableSizeForCustomCapacity() { assertEquals(INITIAL_CAPACITY, IntHashMap.tableSize(1)); assertEquals(MAXIMUM_CAPACITY, IntHashMap.tableSize(Integer.MAX_VALUE)); }
static int tableSize(int cap) { int n = cap - 1; n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16; return (n < INITIAL_CAPACITY) ? INITIAL_CAPACITY : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; }
IntHashMap implements IntMap<V> { static int tableSize(int cap) { int n = cap - 1; n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16; return (n < INITIAL_CAPACITY) ? INITIAL_CAPACITY : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; } }
IntHashMap implements IntMap<V> { static int tableSize(int cap) { int n = cap - 1; n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16; return (n < INITIAL_CAPACITY) ? INITIAL_CAPACITY : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; } IntHashMap();  IntHashMap(int cap); }
IntHashMap implements IntMap<V> { static int tableSize(int cap) { int n = cap - 1; n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16; return (n < INITIAL_CAPACITY) ? INITIAL_CAPACITY : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; } IntHashMap();  IntHashMap(int cap); @Override V get(int key); @Override V put(int key, V val); @Override V remove(int key); @Override V putIfAbsent(int key, V val); @Override void forEach(EntryConsumer<V, E> act); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(int key); @Override boolean containsValue(V val); @Override String toString(); }
IntHashMap implements IntMap<V> { static int tableSize(int cap) { int n = cap - 1; n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16; return (n < INITIAL_CAPACITY) ? INITIAL_CAPACITY : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; } IntHashMap();  IntHashMap(int cap); @Override V get(int key); @Override V put(int key, V val); @Override V remove(int key); @Override V putIfAbsent(int key, V val); @Override void forEach(EntryConsumer<V, E> act); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(int key); @Override boolean containsValue(V val); @Override String toString(); static final int INITIAL_CAPACITY; static final int MAXIMUM_CAPACITY; }