Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- theHashTable.insert("aa", "ab");
- private class HashTable {
- private class Value {
- ArrayList<String> fileNames;
- String word;
- Value() {
- fileNames = new ArrayList<String>();
- }
- }
- private int currentSize = 101;
- private Value[] items;
- private HashTable() {
- items = new Value[currentSize];
- for (int i = 0; i < currentSize; i++) items[i] = new Value();
- }
- private int hash(String in) {
- int out = 0;
- for (int i = 0; i < in.length(); i++) out += 37*out+in.charAt(i);
- out %= currentSize;
- if (out < 0) out += currentSize;
- return out;
- }
- public void insert(String inW, String inF) {
- int index = hash(inW);
- index = 0;
- if (items[index].word.length() == 0) {
- items[index].word = inW;
- items[index].fileNames.add(inF);
- }
- else if (items[index].word.compareTo(inW) == 0) items[index].fileNames.add(inF);
- else System.out.println("Collision");
- }
- }
- ArrayList<String> fileNames = new ArrayList<String>();
Add Comment
Please, Sign In to add comment