public class HashTable implements Table { private Object head[]; public int nodecount = 0; public long getitcount = 0; public int buckets; public HashTable(int i) { buckets = i; head = new Object[i]; } public HashTable() { buckets = 256; head = new Object[buckets]; } public void put(K key, V value) { int hash = key.hashCode() % buckets; Node n = new Node(key, value, (Node)head[hash]); head[hash]=n; nodecount++; } public V get(K key) { int hash = key.hashCode() % buckets; for (Node n = (Node)head[hash]; n != null; n = n.next) { getitcount++; if (key.equals(n.key)) return n.value; } return null; } public void remove(K key) { int hash = key.hashCode() % buckets; if (head[hash]!=null) { if (key.equals(((Node)head[hash]).key)) { head[hash] = ((Node)head[hash]).next; } for (Node n = (Node)head[hash]; n!=null && n.next != null; n = n.next) { if (key.equals(n.next.key)) { n.next = n.next.next; } } } } private class Node { private K key; private V value; private Node next; Node(K k, V v, Node l) { key = k; value = v; next = l; } } }