Debian Codegraph @

src/internal/abi/map_noswiss.go

raw
1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package abi
6
7 import (
8 "unsafe"
9 )
10
11 // Map constants common to several packages
12 // runtime/runtime-gdb.py:MapTypePrinter contains its own copy
13 const (
14 // Maximum number of key/elem pairs a bucket can hold.
15 OldMapBucketCountBits = 3 // log2 of number of elements in a bucket.
16 OldMapBucketCount = 1 << OldMapBucketCountBits
17
18 // Maximum key or elem size to keep inline (instead of mallocing per element).
19 // Must fit in a uint8.
20 // Note: fast map functions cannot handle big elems (bigger than MapMaxElemBytes).
21 OldMapMaxKeyBytes = 128
22 OldMapMaxElemBytes = 128 // Must fit in a uint8.
23 )
24
25 type OldMapType struct {
26 Type
27 Key *Type
28 Elem *Type
29 Bucket *Type // internal type representing a hash bucket
30 // function for hashing keys (ptr to key, seed) -> hash
31 Hasher func(unsafe.Pointer, uintptr) uintptr
32 KeySize uint8 // size of key slot
33 ValueSize uint8 // size of elem slot
34 BucketSize uint16 // size of bucket
35 Flags uint32
36 }
37
38 // Note: flag values must match those used in the TMAP case
39 // in ../cmd/compile/internal/reflectdata/reflect.go:writeType.
40 func (mt *OldMapType) IndirectKey() bool { // store ptr to key instead of key itself
41 return mt.Flags&1 != 0
42 }
43 func (mt *OldMapType) IndirectElem() bool { // store ptr to elem instead of elem itself
44 return mt.Flags&2 != 0
45 }
46 func (mt *OldMapType) ReflexiveKey() bool { // true if k==k for all keys
47 return mt.Flags&4 != 0
48 }
49 func (mt *OldMapType) NeedKeyUpdate() bool { // true if we need to update key on an overwrite
50 return mt.Flags&8 != 0
51 }
52 func (mt *OldMapType) HashMightPanic() bool { // true if hash function might panic
53 return mt.Flags&16 != 0
54 }