CMSC 420 Section 0401 - Programming Assignment 1, Part D
GonnetMunro Scheme on Double Hashing
Due April 14, 11:45PM
Overview
In part D, you will extend the work you did in parts A, B, and C.
- You need to update your implementation of
HashTable.java of part B to be GonnetMunroHashTable.java in order to
support the Gonnet-Munro variation
- You also need to provide a driver class
Gonnet-Munro HashTablePlotData.java, which will generate gnuplot
data.
The plots will attempt to (empirically) show that the extra effort in
Gonnet-Munro programming (quantified by the graph moves.ps) is worth the benefit (for
example, see longest.ps).
Details
Recall that in parts A and B, you wrote HashTable.java.
In part C, you need to implement the class
AbstractGonnetMunroHashTable
which extends AbstractHashTable.
Note that the AbstractHashTable.java here is the same as it in
part B.
Your implementation should be named GonnetMunroHashTable as shown below:
public class GonnetMunroHashTable extends AbstractGonnetMunroHashTable {
public GonnetMunroHashTable (int tableSize);
private GonnetMunroHashTable ();
// Methods in Part B
public int getSize ();
// hashValue(String key) and probleHashValue(String key)
// are inherited from AbstractHashTable.
public int hashValue (String key);
public int probeHashValue (String key);
public int probeCount; // doesn't need to declare, inherited from AbstractHashTable.
public boolean put (String key, Object value);
public boolean containsKey (String key);
public boolean remove (String key);
public Object get (String key);
// You may need to modify longestProbe() for GonnetMunroPut()
public int longestProbe ();
// New data member in Part D
public int gonnetMunroMoveCount;
// New method in Part D
public boolean gonnetMunroPut (String key, Object value);
}
Observe that in part D, a new method and a new instance variable has been defined:
- public boolean gonnetMunroPut (String key, Object value):
Maps the specified key to the specified value
in this GonnetMunroHashTable by Gonne-Munro scheme of double hashing.
Note that you do NOT need to increase probeCount for each probe
in gonnetMunroPut as in other methods in part B.
Note that your longestProbe() need not take O(1) constant
time when your gonnetMunroPut is introduced.
- You need to increase gonnetMunroMoveCount by 1 whenever an item is
moved.
- Your implementation must avoid integer overflow as well as require
reasonable time and memory. The class java.math.BigInteger may help for
your implementation.
Next the driver. The driver class GonnetMunroTablePlotData will
output a gnuplot data file which in turn will generate a PostScript file
like
success.ps,
longest.ps, and
moves.ps.
The goal is to produce charts of average cost(probes) of successful
search with collisions handled by GonnetMunro scheme of double hashing.
How do we produce these files?
- Your program will be executed as "java GonnetMunroHashTablePlotData putfile
", where putfile are text
files containing items (keys and elements).
- As in parts B and C, the putfile contains key-value pairs (i.e.,
items with keys
and elements) to be inserted in the table.
Each line in this file contains the a key and its mapped element
(values are separated by spaces in our sample input. You may
assume the leading character of each line is not
a space.)
For full credit, search cost of duplicate keys should
not be counted in average search cost.
- The output, consisting of multiple data records, is printed to
the standard
output stream (System.out in Java).
Each line contains a record corresponding to a table size/capacity
from 2, 3, 5, to the largest prime less than or equal to the number
of distinct keys in putfile.
Note that the loading factor is 100% (full loaded).
For table size m, insert the first m distinct keys in
putfile into the table using gonnetMunroPut.
You may use standard error stream (System.err in Java) for
debugging purpose.
- Each record has four fields separated
by spaces in sequence:
(1) table size/capacity,
(2) average successful search cost of double hashing
(3) length of longest successful probe sequence, and
(4) average number of moves made by gonnetMunroPut.
Use probeCount and gonnetMunroMoveCount wisely to implement
GonnetMunroHashTablePlotData.
That basically finishes your programming task. Here is some post
processing. Visualization is accomplished with gnuplot. You can
figure out how this works by the examples provided below.
- The driver is run using
"java GonnetMunroHashTablePlotData put199 > plot199" with putfile
put199. Here 199 means the number
of items in the putfile.
- The type of output we are looking for is here: plot199.
- Using the shell command "gnuplot plotps1" with the script file
plotps1,
you get the file success.ps.
- Here is, finally, one of the files we actually want
success.ps.
Note that you need to put required files in the current directory.
- Likewise, you may get the chart of the length of the longest probe
sequence longest.ps by
"gnuplot plotps2" with
plotps2.
- Likewise, you may get the chart of the average number of moves
in the Gonnet-Munro scheme
moves.ps using the command
"gnuplot plotps3" with
plotps3.
- You may assume the
putfile always with name putxxx, where xxx is the number
of (possibly duplicate) keys in the file.
Grading:
- The maximum points of part D is 100.
- Grading will focus on the the new method of GonnetMunroHashTable
the increment of gonnetMunroMoveCount, and the
class GonnetMunroHashTablePlotData and your prediction of theoretical
B(m). However, bugs in parts A, B and/or C
may break the functionality required in this part.
- The public drivers for grading will be posted soon.
- [4/9/01 Added by TA:] Public driver
GonnetMunroHashTableDriver1.java
is available now. Max points are 20.
- [4/10/01 Added by TA:]
"java GonnetMunroHashTablePlotData put19 > myplot" with
putfile put19 and your
GonnetMunroHashTablePlotData.java.
And "java ColumnCompare plot19 myplot 0 5 5 5" with
plot19 and
ColumnCompare.java
to see your score. Max points are 15.
- [4/10/01 Added by TA:]
"java GonnetMunroHashTablePlotData put199 > myplot" with
putfile put199 and your
GonnetMunroHashTablePlotData.java.
And "java ColumnCompare plot199 myplot 0 5 5 5" with
plot199 and
ColumnCompare.java
to see your score. Max points are 15.
- [5/10/01 Added by TA:] All the public drivers
are in p1d_drivers.tar.gz
Submission:
- Tar and gzip your *.java files,
and submit.
- Submission is handled using the submit program with submission index 4.
Ex: "~sc42002/bin/submit 4 foo.tar.gz".
- I(TA) reserve the right to deduct up to 10 points if you don't follow
the submission procedure.
- [4/12/02 added by TA:]
The late penality table of late submission of Part D is as follows:
| Late submission in
hours | 0-6 hours | 6-12 hours | 12-18 hours | 18-24 hours | 1-2
days | 2-3 days | 3-6 days | late for more
than 6 days |
| Penality | 1% | 2% | 4% | 8% | 16% | 32% | 64% | won't be
accepted |
Web Accessibility