//--------------------------------------------------------- // The hashTable class implements a hash table that can // store any objects that implement a hashcode function // and a key_equal function: // // unsigned int hashcode() // // The hashcode function must return an unsigned integer // value. This value will be used to determine the location // of the object that invokes the function. The hashcode // function converts the key field value of the object into // an unsigned integer. Given equal key values, the hashcode // function must return the same unsigned integer result. // // bool key_equal(const itemType& item) // // The key_equal function for an object returns true if the // object that invokes the function has the same key field // value as the function parameter and false otherwise. // // When searching for an item, the hashcode function will // be invoked for that item to determine the bucket in // which the item would be located if it was in the table. // The key_equal function will be used to determine if // the item is included in that bucket. // // The size of the hash table (see the constructors) is the // number of buckets in the hash table. A hash table can // hold any number of items (even more than its size). // However, as the number of items increases beyond the // size, search operations will become slightly less // efficient. //--------------------------------------------------------- template class hashTable { private: list* table; int size; public: //----------------------------------------------------- // Construct a hash table with a size of 53 //----------------------------------------------------- hashTable() { } //----------------------------------------------------- // Construct a hash table of the specified size. // // Precondition: theSize > 0; // // In Parameter: theSize //----------------------------------------------------- hashTable(int theSize) { } //----------------------------------------------------- // Destroy the hash table and release all allocated // memory back to the operating system. //----------------------------------------------------- ~hashTable() { } //----------------------------------------------------- // Insert the specified item into the hash table. // // Precondition: There is no item in the table with the // same key field value as the specified item. Before // inserting an item into the table, the application // should search for the item to make sure it is not // already in the table. // // In Parameter: item //----------------------------------------------------- void insert(itemType item) { } //----------------------------------------------------- // Search for an item in the table whose key value // matches the key value of the specified item (as // determined by the key_equal function in the item // class). If found, this function returns a pointer // to the item. Otherwise, this function returns a // NULL pointer. // // In Parameter: targetItem //----------------------------------------------------- itemType* search(itemType targetItem) { } //----------------------------------------------------- // Convert this hash table to a list and return the // list as an out parameter. // // Postcondition: the list will contain the same items // as the table. The table will not be modified in // any way. // // Out Parameter: list //----------------------------------------------------- void toList(list& theList) { } };