EECS 360 - Machine Problem 4
Hashing
Due: 11:59 pm on Thursday 10/26/2000
For this assignment you must work alone.
For this assignment, you are to add, find and remove strings
from a open addressing hash table. The hash table will be allowed
to change size, but must always have a prime number for its size. The initial
size of the hash table is to be 53. To resolve collisions, we will
use a double hashing routine. The primary hash function to be used
is the one discussed in the book in firgure 5.5. The secondary hash
routine used with the double hashing routine is to use the next smallest
prime number from the size of the table for the value of R in the formula
discussed in class and the book.
The program is to be interactive. The commands will
be similar to what was used in MP3. The biggest difference is that
the values used will be strings and not integers. The next difference
is that white space will be used instead of commas to seperate multiple
strings. We will implement the following operations:
-
a <el1> <el2> <el3> ... <elN>
-
Add all N elements to the hash table. If a collision occurs while adding
the element, print a message stating the number of hash table positions
that had to be examined before the element could be inserted. An
error message should be printed if an element that is already in the hash
table is attempted to be added. The elements are to be added to the
hash table in the order they are given.
-
c
-
Clear all elements from hash table.
-
f <el1> <el2> <el3> ... <elN>
-
Find all N elements in the hash table. For each element, print a message
whether the element was found or not found.
-
r <el1> <el2> <el3> ... <elN>
-
Remove all N elements from the hash table. An error message should be printed
if an element that is not in the hash table is attempted to be removed.
If a collision occurs while deleting the element, print a message stating
the number of hash table positions that had to be examined before the element
could be deleted. The elements are to be removed from the trees
in the order they are given.
-
s <int>
-
The hash table to change size to be the next largest prime number greater
than or equal to the integer value given in the command. The current
hash table is to be "rehashed" into the hash table of this new size.
You must use dynamic array allocation to create the new hash table and
deallocate to old hash table when it is no longer needed. When the
command is finished print a meesage stating how many collosions occurred
during the rehashing operation.
-
-
w <filename>
-
Write out the contents of the current hash table to the indicated file.
The first line of the file should have the string stored at position zero
and the last line of the file should have the string stored a position
(size -1). The file should the hash table position listed before
the string is printed. You may (but are not required to) print out
the "KindOfEntry" information associated with that position after the string.
-
i
-
List the current size of the hash table, the number of elements in the
hash table, the percent of positions that have an element.
-
q
-
Quit the program. Print an appropriate good-bye message upon completion
of your program.
The input for the program will be given through standard input. Each line
of input will have one and only one operation. Each operation will fit
on one line of input. You may assume that each line is no more than 100
characters long. The first non-white space character will be the character
for the operation. If an unknown character is given, print out an error
message such as Operation X is not known and ignore the rest
of the the input line. White space characters are the space an tab characters.
You may assume that each string is 30 characters or less in length.
Since this program is to be interactive, your program is to prompt the
user for each command.
General Comments
Your program must be written in good programming style. This includes
(but is not limited to) meaningful identifier names, a file header at the
beginning of each source code file, a function header at the beginning
of the function, proper use of blank lines and indentation to aide in the
reading of your code, explanatory "value-added" in-line comments, etc.
The work you turn in must be 100% done by your own own. You are not
allowed to share code with any other students (inside this class or not).
You may discuss the project with other students; however, you may not show
any code you write to another student nor may you look at any other student's
written code.
You are to submit this project using the EECS Department's UNIX machine's
turnin command. The project name for this assignment is mp4. Be
sure to submit all source code and header files and makefile. Failure to
turnin all required pieces will result in a lower grade for the assignment.
The turnin command for this assignment is:
turnin -c eecs360a -p mp4 <file list>
where <file list> is the names of all files that you will submit for
this program. You can use the turnin command multiple times; however, ever
time you must submit all files needed for the program. To see which files
you have submitted to turnin use the -v option with the turnin command
as follows:
turnin -c eecs360a -p mp4 -v