Skip to content

Instantly share code, notes, and snippets.

@rezamt
Created April 29, 2019 14:17
Show Gist options
  • Save rezamt/dd38383bf183a0cb93ca1ec7979df608 to your computer and use it in GitHub Desktop.
Save rezamt/dd38383bf183a0cb93ca1ec7979df608 to your computer and use it in GitHub Desktop.
HashFunction
private static class HashFunction {
private long prime;
private long odd;
public HashFunction(final long prime, final long odd) {
this.prime = prime;
this.odd = odd;
}
public int getHashValue(final Character character) {
int hash = character.hashCode();
if (hash < 0) {
hash = Math.abs(hash);
}
return calculateHash(hash, prime, odd);
}
private int calculateHash(final int hash, final long prime, final long odd) {
return (int)((((hash % LIMIT) * prime) % LIMIT) * odd) % LIMIT;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment