package compiler // This file contains functions that are also used by the runtime. These must be // kept in sync. // 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 hashmapHash(data []byte) uint32 { var result uint32 = 2166136261 // FNV offset basis for _, c := range data { result ^= uint32(c) result *= 16777619 // FNV prime } return result } // Get the topmost 8 bits of the hash, without using a special value (like 0). func hashmapTopHash(hash uint32) uint8 { tophash := uint8(hash >> 24) if tophash < 1 { // 0 means empty slot, so make it bigger. tophash += 1 } return tophash }