Move hashmap creation to runtime

This commit is contained in:
Ayke van Laethem
2018-08-23 23:12:27 +02:00
parent ae2fc3c8a7
commit 005665aee6
2 changed files with 17 additions and 36 deletions
+12
View File
@@ -42,6 +42,18 @@ func stringhash(s *string) uint32 {
return result
}
// Create a new hashmap with the given keySize and valueSize.
func hashmapMake(keySize, valueSize uint8) *hashmap {
bucketBufSize := unsafe.Sizeof(hashmapBucket{}) + uintptr(keySize)*8 + uintptr(valueSize)*8
bucket := alloc(bucketBufSize)
return &hashmap{
buckets: bucket,
keySize: keySize,
valueSize: valueSize,
bucketBits: 0,
}
}
// Set a specified key to a given value. Grow the map if necessary.
func hashmapSet(m *hashmap, key string, value unsafe.Pointer) {
hash := stringhash(&key)