Created
March 1, 2021 18:00
-
-
Save tejzpr/bb2cfe54f4f28a2003f09658362d6dd4 to your computer and use it in GitHub Desktop.
FNV Hash - Go
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
package main | |
import "fmt" | |
func fnvHash32(key string) uint32 { | |
hash := uint32(2156825496) | |
const prime32 = uint32(16777619) | |
for i := 0; i < len(key); i++ { | |
hash *= prime32 | |
hash ^= uint32(key[i]) | |
} | |
return hash | |
} | |
func main() { | |
fmt.Println(fnvHash32("Hello World!")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment