コード例 #1
0
 private static void hashQuery(
     LinkedList<LinkedList<Anagram>>[] dictList, Scanner queryScan, PrintWriter outputWriter) {
   Anagram queryItem;
   int index;
   LinkedList<Anagram> printPoint;
   while (queryScan.hasNext()) {
     printPoint = null;
     queryItem = new Anagram(queryScan.nextLine());
     index = queryItem.cantorHash();
     if (dictList[index] != null) {
       for (LinkedList<Anagram> a : dictList[index]) {
         if (queryItem.getKey().compareTo(a.peek().getKey()) == 0) {
           printPoint = a;
           break;
         }
       }
     }
     writeAnagramsToFile(printPoint, outputWriter, queryItem);
   }
 }
コード例 #2
0
 private static int hashStash(String input, LinkedList<LinkedList<Anagram>>[] dictList) {
   int collCount = 0;
   Anagram addition = new Anagram(input);
   // int index = Math.abs(addition.getKey().hashCode()) % 199967;
   int index = addition.cantorHash();
   // int index = Math.abs(input.hashCode()) % 199967;
   if (dictList[index] == null) {
     dictList[index] = new LinkedList<LinkedList<Anagram>>();
   }
   for (LinkedList<Anagram> a : dictList[index]) {
     if (a.peek() != null && addition.getKey().equals(a.element().getKey())) {
       a.addFirst(addition);
       return collCount;
     }
     collCount++;
   }
   dictList[index].addFirst(new LinkedList<Anagram>());
   dictList[index].element().addFirst(addition);
   return collCount;
 }