compiler: support compile-time hashmap with int keys

This commit is contained in:
Ayke van Laethem
2018-09-15 01:03:22 +02:00
parent 152e12e4b0
commit 38efc5653d
2 changed files with 19 additions and 5 deletions
+3 -3
View File
@@ -6,10 +6,10 @@ package main
// Get FNV-1a hash of this string.
//
// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash
func stringhash(s *string) uint32 {
func hashmapHash(data []byte) uint32 {
var result uint32 = 2166136261 // FNV offset basis
for i := 0; i < len(*s); i++ {
result ^= uint32((*s)[i])
for _, c := range data {
result ^= uint32(c)
result *= 16777619 // FNV prime
}
return result