// Textbook fragment 09.04 /** Returns the number of entries in the hash table. */ public int size() { return n; } /** Returns whether or not the table is empty. */ public boolean isEmpty() { return (n == 0); } /** Returns an iterable object containing all of the keys. */ public Iterable keys() { PositionList keys = new NodePositionList(); for (int i=0; i e = bucket[i]; if ( e == null) { if (avail < 0) avail = i; // key is not in table break; } if (key.equals(e.getKey())) // we have found our key return i; // key found if (e == AVAILABLE) { // bucket is deactivated if (avail < 0) avail = i; // remember that this slot is available } i = (i + 1) % capacity; // keep looking } while (i != j); return -(avail + 1); // first empty or available slot } /** Returns the value associated with a key. */ public V get (K key) throws InvalidKeyException { int i = findEntry(key); // helper method for finding a key if (i < 0) return null; // there is no value for this key return bucket[i].getValue(); // return the found value in this case }