Created
August 24, 2017 16:18
-
-
Save fenimore/0bec949e33c6399ba76fa45e67cf864f to your computer and use it in GitHub Desktop.
Hash Function for Hash Table
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
var TABLE_SIZE = 512 | |
func hash(s string) int { | |
hash := 0 | |
length := len(s) | |
prime := 233 | |
for i := 0; i < length; i++ { | |
hash += prime^(length-i+1) * int(s[i]) | |
hash = hash % TABLE_SIZE | |
} | |
return hash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment