Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Dec 16th, 2012  |  syntax: None  |  size: 1.09 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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>();