Topics: Hash Tables - Theory and Practice
The assignment has three parts. In Parts 1 and 2, you code and test hash tables based on chaining and open addressing, respectively. Part 3 consists of exercises on hash tables.
In Part 1, implement a ChainHash class that handles collision resolution via chaining. Implement the insert, delete, and search operations, as well as a ShowTable method (see below).
How to Test. You will test your hash table operations on files I provide, containing commands to invoke the various dictionary operations. These operations are:
|c||construct an empty table (done in the command interpreter)|
|i key||insert node with key key into the table|
|d key||delete node with key key from the table|
|s key||search for node with key key in the table|
|S||Show (display) the table structure|
|#||echo the comment line|
Initially in the command interpreter constructs an empty hash table on which all subsequent operations will be performed. The 'i', 'd', and 's' commands work just as described in Chapter 11. The 'S' command Shows the hash table structure: for each slot, print the linked list using the Show() method in the linked list class, LList. Finally, a line beginning with a '#' the line is interpreted as a comment and simply echoed to standard output. Lines beginning with any other character are ignored.
For Part 1, use m = 9, and hash function h(k) = k mod 9.
You can use a modified command interpreter from previous labs. For the tests that you hand in, commands will be processed in batch mode (i.e., read from files). However, you may want to modify the command interpreter so that it can read commands from standard input as well so that you can more conveniently test simple operations in the early stages.
Helpful code: Here is a .h file for the LList class llist.h, and code for the linked list class implementation llist.cpp. Here is a .h file for the ChainHash class chainhash.h, and skeleton code for the chained hash class implementation chainhash.cpp. Here is a command interpreter: cmdint.cpp. Here is a "Makefile" that puts it all together: Makefile. When you download these files, be sure to remove the ".txt" suffixes (by moving them to the same file name without the ".txt").
For Part 2, use m = 11, and linear probing with hash function h(k,i) = (h'(k) + i) mod 11, where the auxiliary hash function h'(k) = k mod 11.
Helpful code: Here is a .h file for the OpenHash class openhash.h, and skeleton code for the chained hash class implementation openhash.cpp. Here is a command interpreter for Part 2: cmdint2.cpp. Here is a "Makefile" that puts it all together: Makefile2. When you download these files, be sure to remove the ".txt" suffixes (by moving them to the same file name without the ".txt"). Also you probably want to put the files in a different directory than those of Part 1. Finally, if you use the makefile, be sure to save it as "Makefile" (i.e. without the suffix "2.txt").