package tsp.hashmap; public class HashMap implements Map { private Map[] table; private int size = 0; private final double loadFactor = 0.75; public HashMap() { table = new Map[5]; /* the only type unsafe operation of the application */ for(int i=0; i(null, null); } private Map getList(K key) { int code = key.hashCode() % table.length; if(code < 0) code += table.length; return table[code]; } public V get(K key) { return getList(key).get(key); } public boolean put(K key, V value) { boolean wasInMap = getList(key).put(key, value); if (wasInMap) size++; if (size > this.table.length * loadFactor) resize(); return wasInMap; } public boolean remove(K key) { boolean wasInMap = getList(key).remove(key); if (wasInMap) size--; return wasInMap; } public void display() { for(int i=0; i map) { for (int i = 0; i < map.table.length; i++){ map.table[i].addAllTo(this); } } @Override public int getSize() { return this.size; } public HashMap(int capacity) { table = new Map[capacity]; /* the only type unsafe operation of the application */ for(int i=0; i(null, null); } public void resize() { int newCapacity = this.table.length * 2; HashMap newHashMap = new HashMap<>(newCapacity); for (int i = 0; i < this.table.length; i++){ this.table[i].addAllTo(newHashMap); } this.table = newHashMap.table; } }