Skip to content

Instantly share code, notes, and snippets.

@fenimore
Created August 24, 2017 16:18
Show Gist options
  • Save fenimore/0bec949e33c6399ba76fa45e67cf864f to your computer and use it in GitHub Desktop.
Save fenimore/0bec949e33c6399ba76fa45e67cf864f to your computer and use it in GitHub Desktop.
Hash Function for Hash Table
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