import java.io.*; import java.lang.*; abstract public class AbstractHashTable { // In your implementation, the constructor must take an int argument // as table size. If the argument is negative or not a prime, set // the table size to be the smallest integer. // This hash table in this programming assignment is not expandable. // Returns the size of hash table. abstract public int getSize(); // For grading purpose, the public variable probeCount is incrememted // by 1 whenever a probe was made, useful or useless, as // put/containsKey/remove routines are called. public int probeCount; // Set hash argument to convert strings. See slide 3 of hashing // lecture notes. By default, the argument a = 37. abstract public void setHashArgument( int a ); // Set the arguments of MAD method h(k)=a*k+b mod m. // By default, a=1 and b=0. // If given a is a multiple of table size, which is a prime number, // then set a=1 instead. // For full credits, you need to take care of negative a and b. abstract public void setMADArguments( int a, int b ); // Returns true if the input i is a prime; otherwise return false. public static boolean isPrime( int i ) { if( i <= 1 ) return false; for( int j = (int)Math.sqrt((double)i); j>1; j-- ) if( i%j == 0 ) return false; return true; } // Returns the hash value of the given key. // See Horner's rule and MAD method in lecture slides. abstract public int hashValue( String key ); // In this programming assignment, you are asked to handle collisions // with open addressing by double hashing. Thus you need the other hash // function for probing. See lecture slides. // Returns the hash value of the given key for probing. abstract public int probeHashValue( String key ); // Note that in the following 3 routines, you need to call // probeHashValue(key) to get probing offset for full credits. // Maps the specified key to the specified value in this hashtable. // Returns true if succeed, false if failed. abstract public boolean put( String key, Object value ); // Tests if the specified string is a key in this hashtable. abstract public boolean containsKey( String key ); // Removes the key (and its corresponding value) from this hashtable. // Return true if succeed, false if not found. abstract public boolean remove( String key ); }