Chnaged hash method for dictionary to hash cod + mad

This commit is contained in:
2014-05-13 10:38:13 +02:00
parent 5099e8d1af
commit 867a7c1a53
7 changed files with 107 additions and 81 deletions

View File

@@ -1,8 +1,7 @@
package com.xgiovio;
import dictionary.HashDictionaryChaining;
import dictionary.Logfile;
import exceptions.EmptyListException;
import dictionary.ChainingHashTable;
import dictionary.LogFile;
import priorityqueue.Entry;
import java.security.InvalidKeyException;
@@ -14,13 +13,11 @@ import java.util.Iterator;
* Date: 11/05/2014
* Time: 21:17
*/
public class HashDictionaryChainingTest {
public class ChainingHashTableTest {
public static void main(String[] args) throws InvalidKeyException{
Logfile<String,Integer> def = new Logfile<String, Integer>();
HashDictionaryChaining<String,Integer> h = new HashDictionaryChaining<String, Integer>(def,5);
ChainingHashTable<String,Integer> h = new ChainingHashTable<String, Integer>();
System.out.println(h.load_factor());

View File

@@ -1,6 +1,6 @@
package com.xgiovio;
import dictionary.HashDictionaryLinearProbing;
import dictionary.LinearProbingHashTable;
import priorityqueue.Entry;
import priorityqueue.MyEntry;
@@ -13,13 +13,11 @@ import java.util.Iterator;
* Date: 11/05/2014
* Time: 21:17
*/
public class HashDictionaryLinearProbingTest {
public class LinearProbingHashTableTest {
public static void main(String[] args) throws InvalidKeyException{
MyEntry<String,Integer> def = new MyEntry<String, Integer>("null",0);
HashDictionaryLinearProbing<String,Integer> h = new HashDictionaryLinearProbing(def,5);
LinearProbingHashTable<String,Integer> h = new LinearProbingHashTable();
System.out.println(h.load_factor());

View File

@@ -1,31 +0,0 @@
package com.xgiovio.hash;
/**
* Created with MONSTER.
* User: xgiovio
* Date: 11/05/2014
* Time: 19:25
*/
public class functions {
//http://m.smithworx.com/cs235/notes/view.php?file=extra%20notes/rodham/35-36-com.xgiovio.hash-tables/HashFunctions.java
public static int hash_horner( String key, int tableSize ) {
int hashVal = 0;
for ( int i = 0; i < key.length(); ++i ) {
hashVal = (hashVal * 37) + key.charAt( i );
}
hashVal %= tableSize;
if ( hashVal < 0 ) {
hashVal += tableSize;
}
return hashVal;
}
}