CSCI 311 – Spring 2012 - Program
1
Dynamic Hashing
Dr. Melody
Stapleton, Instructor
Bonnie Varghese,
Teaching Assistant
Due Date: All Program Components: Sunday,
February 26, uploaded by midnight
Your TA, Bonnie, will provide the
final input file(s) to run your program against by Thursday, Feb. 16.
Bonnie will also provide documentation, and style guidelines in the labs.
Your are to implement the
Dynamic Hashing Algorithm, as discussed in class and posted in the course notes
on the web using appropriate C++ classes.
You are to
structure your main program to accept and interpret file input according to the
following:
Be sure to echo each input line of your input file immediately after reading that line.
You will need to
write your program to first accept the power of 2 (from the input file, on the
first line) that will be used for the hash function mod value. Be sure to
return the error: ”Value is not a power of
2” to the user if they do not enter a power of 2 and then halt execution
of (exit) the program. Return the error to the output file. The
next line on the input file will be the bucket size to be used for each bucket.
Listed below are
the possibilities for the different categories of commands that will follow the
above 2 lines:
You will, of
course, need to write a hash function, and you will need to create a Dynamic_Hash class that has at least the following member
functions:
Note: You will need to implement
"chaining to overflow buckets" as discussed in class and shown in the
course notes.
Output: Send your output for this
program to a file. Follow precisely the format for output described
above.
Also Note: You are responsible to write
a program that deals with *all cases*. That is, your program should not
only *work good on some input files*, it need to work on *all possible* input
files. This means it is not your TAs responsibility to give you an input
file that allows your program to work. It is your responsibility to write
code that cannot be broken by any input file and so will work in all
cases. This will be the case for every program you write for this course.
A sample file
follows that adheres to the input file format: In the left column you find the values
in the input file. In the right
hand column is the correct output for this sequence of input.
Your homework for Thursday, 2/3/2012 is to finish off
this output listing!!!
Input on left: Output
that should be generated from this input:
|
8 |
8 |
|
|
|
|
2 |
2 |
|
|
|
|
P |
P |
|
|
Hash is empty |
|
D 100 |
D 100 |
|
|
Illegal attempt
to delete a value not present: 100 |
|
S 99 |
S 99 |
|
|
Value not found:
Hash is empty |
|
I 46 |
I 46 |
|
|
Succesful insertion of 46 No pseudokey 46 |
|
P |
P |
|
|
No pseudokey 46 |
|
I 55 |
I 55 |
|
|
Successful
insertion of 55 No pseudokey 46, 55 |
|
I 46 |
I 46 |
|
|
Illegal attempt
to insert duplicate value: 46 |
|
I 88 |
I 88 |
|
|
Successful
insertion of 88 0 88 |
|
P |
P |
|
|
0 88 1 46, 55 |
|
S 46 |
S 46 |
|
|
Value found: 1
46, 55 |
|
S 99 |
S 99 |
|
|
Value not found:
0 88 |
|
I 99 |
I 99 |
|
|
|
|
D 50 |
D 50 |
|
|
|
|
S 99 |
S 99 |
|
|
|
|
I 200 |
I 200 |
|
|
|
|
P |
P |
|
|
|
|
D 55 |
D 55 |
|
|
|
|
P |
P |
|
|
|
|
I 121 |
I 121 |
|
|
|
|
I 201 |
I 201 |
|
|
|
|
I 300 |
I 300 |
|
|
|
|
I 400 |
I 400 |
|
|
|
|
I 500 |
I 500 |
|
|
|
|
S 300 |
S 300 |
|
|
|
|
P |
P |
|
|
|
|
D 500 |
D 500 |
|
|
|
|
D 46 |
D 46 |
|
|
|
|
P |
P |
|
|
|
|
D 200 |
D 200 |
|
|
|
|
D 88 |
D 88 |
|
|
|
|
P |
P |
|
|
|
|
D 121 |
D 121 |
|
|
|
|
D 99 |
D 99 |
|
|
|
|
P |
P |
|
|
|
|
D 300 |
D 300 |
|
|
|
|
D 400 |
D 400 |
|
|
|
|
D 201 |
D 201 |
|
|
|
|
P |
P |