IntHashMap implements IntMap<V> { protected int distance(int curIdx, int key) { int keyIdx = index(key); return curIdx >= keyIdx ? curIdx - keyIdx : entries.length - keyIdx + curIdx; } 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; }
@Test public void distance() { HashMap<Integer, Integer> bijection = new HashMap<>(); bijection.put(1, 14); bijection.put(2, 14); bijection.put(3, 14); bijection.put(4, 14); bijection.put(5, 14); bijection.put(6, 14); bijection.put(7, 14); bijection.put(8, 14); bijection.put(9, 14); IntHashMap<String> directPositionMap = (IntHashMap<String>)bijectionHashFunctionMap(bijection); directPositionMap.put(1, value(1)); directPositionMap.put(2, value(2)); directPositionMap.put(3, value(3)); directPositionMap.put(4, value(4)); directPositionMap.put(5, value(5)); directPositionMap.put(6, value(6)); directPositionMap.put(7, value(7)); directPositionMap.put(8, value(8)); directPositionMap.put(9, value(9)); assertEquals(0, directPositionMap.distance(14, 1)); assertEquals(1, directPositionMap.distance(15, 1)); assertEquals(2, directPositionMap.distance(0, 1)); assertEquals(3, directPositionMap.distance(1, 1)); assertEquals(4, directPositionMap.distance(2, 1)); assertEquals(5, directPositionMap.distance(3, 1)); assertEquals(15, directPositionMap.distance(13, 1)); }