Guest User

Untitled

a guest
Dec 16th, 2012
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. theHashTable.insert("aa", "ab");
  2.  
  3. private class HashTable {
  4. private class Value {
  5. ArrayList<String> fileNames;
  6. String word;
  7. Value() {
  8. fileNames = new ArrayList<String>();
  9. }
  10. }
  11.  
  12. private int currentSize = 101;
  13. private Value[] items;
  14. private HashTable() {
  15. items = new Value[currentSize];
  16. for (int i = 0; i < currentSize; i++) items[i] = new Value();
  17. }
  18.  
  19. private int hash(String in) {
  20. int out = 0;
  21. for (int i = 0; i < in.length(); i++) out += 37*out+in.charAt(i);
  22. out %= currentSize;
  23. if (out < 0) out += currentSize;
  24. return out;
  25. }
  26.  
  27. public void insert(String inW, String inF) {
  28. int index = hash(inW);
  29. index = 0;
  30. if (items[index].word.length() == 0) {
  31. items[index].word = inW;
  32. items[index].fileNames.add(inF);
  33. }
  34. else if (items[index].word.compareTo(inW) == 0) items[index].fileNames.add(inF);
  35. else System.out.println("Collision");
  36. }
  37. }
  38.  
  39. ArrayList<String> fileNames = new ArrayList<String>();
Add Comment
Please, Sign In to add comment