Implementato HashCode Dictionary via LinearProbing (Open Adress) e Chaining.
This commit is contained in:
31
com/xgiovio/hash/functions.java
Normal file
31
com/xgiovio/hash/functions.java
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user