summaryrefslogtreecommitdiff
path: root/abi/map_swiss.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-19 04:40:49 -0500
committerJeff Carr <[email protected]>2025-03-19 04:40:49 -0500
commit17119d9298e132aa309f1cc95e439f29f61214b0 (patch)
tree578abd95ba2cfe0cdcec3f6e51d609ccb9e2f36b /abi/map_swiss.go
day1v0.0.1
Diffstat (limited to 'abi/map_swiss.go')
-rw-r--r--abi/map_swiss.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/abi/map_swiss.go b/abi/map_swiss.go
new file mode 100644
index 0000000..6c85566
--- /dev/null
+++ b/abi/map_swiss.go
@@ -0,0 +1,64 @@
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package abi
+
+import (
+ "unsafe"
+)
+
+// Map constants common to several packages
+// runtime/runtime-gdb.py:MapTypePrinter contains its own copy
+const (
+ // Number of bits in the group.slot count.
+ SwissMapGroupSlotsBits = 3
+
+ // Number of slots in a group.
+ SwissMapGroupSlots = 1 << SwissMapGroupSlotsBits // 8
+
+ // Maximum key or elem size to keep inline (instead of mallocing per element).
+ // Must fit in a uint8.
+ SwissMapMaxKeyBytes = 128
+ SwissMapMaxElemBytes = 128
+
+ ctrlEmpty = 0b10000000
+ bitsetLSB = 0x0101010101010101
+
+ // Value of control word with all empty slots.
+ SwissMapCtrlEmpty = bitsetLSB * uint64(ctrlEmpty)
+)
+
+type SwissMapType struct {
+ Type
+ Key *Type
+ Elem *Type
+ Group *Type // internal type representing a slot group
+ // function for hashing keys (ptr to key, seed) -> hash
+ Hasher func(unsafe.Pointer, uintptr) uintptr
+ GroupSize uintptr // == Group.Size_
+ SlotSize uintptr // size of key/elem slot
+ ElemOff uintptr // offset of elem in key/elem slot
+ Flags uint32
+}
+
+// Flag values
+const (
+ SwissMapNeedKeyUpdate = 1 << iota
+ SwissMapHashMightPanic
+ SwissMapIndirectKey
+ SwissMapIndirectElem
+)
+
+func (mt *SwissMapType) NeedKeyUpdate() bool { // true if we need to update key on an overwrite
+ return mt.Flags&SwissMapNeedKeyUpdate != 0
+}
+func (mt *SwissMapType) HashMightPanic() bool { // true if hash function might panic
+ return mt.Flags&SwissMapHashMightPanic != 0
+}
+func (mt *SwissMapType) IndirectKey() bool { // store ptr to key instead of key itself
+ return mt.Flags&SwissMapIndirectKey != 0
+}
+func (mt *SwissMapType) IndirectElem() bool { // store ptr to elem instead of elem itself
+ return mt.Flags&SwissMapIndirectElem != 0
+}