The program is suppose to run through a list of strings. The stings are then put through a hash function (which works fine) and then "hashed" (for lack of a better word). The index is suppose to be an array of linked Lists to handle collision problems.
I guess the first question is, what is suppose to be the keys and values? Is the hash function output the keys, or the indexes in the array list; same goes for values. (I've looked through forums and tutorials but nothing really worked)
My understanding is that the output from the function is put in the index of the output modulo the size of the list. H(input) = output, then LinkedList[output] = output...but I'm confused if the hashtable should be hash.put(linkedList[output], output) or some other variation.
Basically, I'm just not sure how to connect the dots between needing the linked list for collisions and hashtable for the keys and values.
My Driver Class:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
public class Driver {
private Hashtable<LinkedList<?>, Integer> hash;
private File fFile;
private LinkedList[] list;
private int count;
public Driver(String info){
hash = new Hashtable<LinkedList<?>, Integer>();
fFile = new File(info);
}
public static void main(String[] args) throws IOException {
Driver d = new Driver("WordData.txt");
d.processLineByLine();
}
public final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(fFile);
list = new LinkedList[222888];
for(int i =0; i < llist.length; i++){
list[i] = new LinkedList();
}
try {
//first use a Scanner to get each line
while (scanner.hasNextLine()) {
String s = scanner.nextLine();
int index = (int) (Hasher.sum(s) % 222888);
hash.put(list[(int) Hasher.sum(s)], index);
System.out.println(hash.keySet() + "\t" + index);
}
}
finally {
//ensure the underlying stream is always closed
scanner.close();
}
}
}
As you can see I'm kinda confused about what should go into the hashtable. Everything else in the program works and does what it's suppose to. I just need help with this part.
The output right now is
[] 673
[] 1123
[] 689
The brackets being what l[(int)Hasher.sum(s)] produces and the numbers being what index produces. Also, Hasher is an outside class that has all my working hash functions.
Any help would be appreciated.