Created
April 29, 2019 14:17
-
-
Save rezamt/dd38383bf183a0cb93ca1ec7979df608 to your computer and use it in GitHub Desktop.
HashFunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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