32 lines
613 B
Java
32 lines
613 B
Java
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;
|
|
}
|
|
|
|
|
|
}
|