// The test harness will belong to the following package; the hash table // implementation will belong to it as well. In addition, the hash table // implementation will specify package access for all data members in order // that the test harness may have access to them. // package Minor.P3.DS; public class HashTable { T[] Table; // stores data objects slotState[] Status; // stores corresponding status values int Size; // dimension of Table int Usage; // # of data objects stored in Table FileWriter Log; // target of logged output boolean loggingOn; // write output iff this is true // Construct hash table with specified size. // Pre: // Sz is a positive integer of the form 2^k. // Post: // this.Table is an array of dimension Sz; all entries are null // this.Status is an array of dimension Sz; all entries are EMPTY // this.Usage == 0 // this.Log == null // this.loggingOn == false // public HashTable(int Sz) { . . . } // Attempt insertion of Elem. // Pre: // Elem is a proper object of type T // Post: // If Elem already occurs in Table (according to equals()): // this.Table is unchanged // this.Usage is unchanged // Otherwise: // Elem is added to Table // this.Usage is incremented // If loggingOn == true: // indices accessed during search are written to Log and // success/failure message is written to Log // Return: reference to inserted object or null if insertion fails // public T Insert(T Elem) throws IOException { . . . } // Search Table for match to Elem (according to equals()). // Pre: // Elem is a proper object of type T // Post: // No member of the hash table object is changed. // If loggingOn == true: // indices accessed during search are written to Log and // success/failure message is written to Log // Return reference to matching data object, or null if no match // is found. public T Find(T Elem) throws IOException { . . . } // Delete data object that matches Elem. // Pre: // Elem is a proper object of type t // Post: // If Elem does not occur in Table (according to equals()): // this.Table is unchanged // this.Usage is unchanged // Otherwise: // matching reference in Table is null // this.Usage is decremented // If loggingOn == true: // indices accessed during search are written to Log and // success/failure message is written to Log // Return reference to deleted object, or null if not found. public T Delete(T Elem) throws IOException { . . . } // Reset hash table to (almost) same state as when first constructed. // Post: // this.Table is an array of dimension Sz; all entries are null // this.Status is an array of dimension Sz; all entries are // EMPTY // this.Opt is unchanged // this.Usage == 0 // this.Log is unchanged // this.loggingOn is unchanged // public void Clear() { . . . } // Reset hash table's log output target. // Pre: // Log is an open on a file, or is null // Post: // If Log is null, no changes are made. // Otherwise: this.Log == Log // Return true iff this.Log has been changed and is not null. // public boolean setLog(FileWriter Log) { . . . } // Turn internal logging on. // Post: // If this.Log is not null, loggingOn == true // Otherwise, loggingOn == false // Returns final value of loggingOn. // public boolean logOn() { . . . } // Turn internal logging off. // Post: // loggingOn == false // Returns final value of loggingOn. // public boolean logOff() { . . . } }