Question: Using ProbeHashTable.java below, write a test program to create a hash table with the default size (61). Import 28 data items (given by a text
Using ProbeHashTable.java below, write a test program to create a hash table with the default size (61). Import 28 data items (given by a text file). The data file "roster.txt" is provided, which contains the offense players of Cleveland Browns and must be imported for the test. Please use the first column, the last name, as the key, and treat the rest of information as value. Please perform the following tasks after the data are imported to the hash table:
- Print out the table in the format of tuples;
- Obtain an iterable instance of key set and then print it out;
- Print out the number of collisions occurred during the data insertion.
roster.txt

import java.util.Iterator;
public class ProbeHashTable extends AbstractHashMap{
private MapEntry[] table;
private MapEntry DEFUNCT = new MapEntry(null, null);
private int count = 0;
public ProbeHashTable() {
super();
}
public ProbeHashTable(int cap) {
super();
}
public ProbeHashTable(int cap,int p) {
super(cap, p);
}
private boolean compareStr(String s, String t) {
count++;
return s.equals(t);
}
protected void createTable() {
table = (MapEntry[]) new MapEntry[capacity];
}
private boolean isAvailable(int i) {
return (table[i] == null || table[i] == DEFUNCT);
}
private int findSlot(int h, String k) {
int available = -1;
int i = h;
do {
if(isAvailable(i)) {
if(available == -1)
available = i;
if(table[i] == null)
break;
}
else if(table[i].getKey().equals(k))
return i;
i = (i + 1) % capacity;
}
while(i != h);
return -(available + 1);
}
protected Object bucketPut(int h, Object key, Object value) {
int i = findSlot(h, (String) key);
if(i
return table[i].setValue((String) value);
table[-(i + 1)] = new MapEntry((String) key, (String) value);
n++;
return null;
}
protected Object bucketGet(int h, Object key) {
int i = findSlot(h, (String) key);
if(i
return null;
return table[i].getValue();
}
protected Object bucketRemove(int h, Object key) {
int i = findSlot(h, (String) key);
if(i
return null;
Object answer = table[i].getValue();
table[i] = DEFUNCT;
n--;
return answer;
}
private class KeyIterable implements Iterable{
public Iterator iterator() {
ArrayList buffer = new ArrayList(n);
for(int i = 0; i
try {
if(!isAvailable(i))
buffer.add(buffer.size(), table[i].getKey());
}
catch(OutOfRangeException e) {
System.out.println("keySet: Out Of Range");
}
return new SArrayIterator(buffer);
}
}
public Iterable keySet() {
return new KeyIterable();
}
public int getCollisions(){
return count;
}
public String toString() {
String str = "";
for (int i = 0; i
str += i + " " + table[i] + " " + table[i].getValue() + " ";
}
return str;
}
}



Mayfield Stanton QB 6' 1" 215 lbs R 6' 3" 226 lbs 12 6' 1"217 lbs 8 5' 11" 227 lbs R Michigan State Virginia Tech 9 3 Hilliard Johnson Jr. Callaway Higgins WR 5' 11" 202 lbs R 5' 11" 200 lbs R Florida 6' 1"198 lbs 3 5' 11" 196 lbs 5 6' 2"215 lbs 3 Colorado State 6' 2"200 lbs R Texas A&M Mari Scott Streater Willies WR 0 Fresno State 2 5 1 6' 4" 207 lbs R 6' 5" 246 lbs 1 6' 3" 257 lbs 3 6' 3" 245 lbs 3 6' 7"270 lbs 5 6' 4" 246 lbs 2 Texas Tech Oregon Charles TE DeValve TE Princeton Tretter c Bitonio Corbett G Watford G Zeitler G Harrison Robinson 6' 4" 307 lbs 6 6' 4" 305 lbs 5 6' 4"306 lbs R 6' 3" 300 lbs 6 6' 4" 315 lbs 7 Corne11 Nevada Nevada James Madison Wisconsin 5 West Georgia Auburn 6' 5"330 lbs 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
