Source file
src/runtime/export_map_noswiss_test.go
1
2
3
4
5
6
7 package runtime
8
9 import (
10 "internal/abi"
11 "unsafe"
12 )
13
14 const RuntimeHmapSize = unsafe.Sizeof(hmap{})
15
16 func OverLoadFactor(count int, B uint8) bool {
17 return overLoadFactor(count, B)
18 }
19
20 func MapBucketsCount(m map[int]int) int {
21 h := *(**hmap)(unsafe.Pointer(&m))
22 return 1 << h.B
23 }
24
25 func MapBucketsPointerIsNil(m map[int]int) bool {
26 h := *(**hmap)(unsafe.Pointer(&m))
27 return h.buckets == nil
28 }
29
30 func MapTombstoneCheck(m map[int]int) {
31
32
33
34 h := *(**hmap)(unsafe.Pointer(&m))
35 i := any(m)
36 t := *(**maptype)(unsafe.Pointer(&i))
37
38 for x := 0; x < 1<<h.B; x++ {
39 b0 := (*bmap)(add(h.buckets, uintptr(x)*uintptr(t.BucketSize)))
40 n := 0
41 for b := b0; b != nil; b = b.overflow(t) {
42 for i := 0; i < abi.OldMapBucketCount; i++ {
43 if b.tophash[i] != emptyRest {
44 n++
45 }
46 }
47 }
48 k := 0
49 for b := b0; b != nil; b = b.overflow(t) {
50 for i := 0; i < abi.OldMapBucketCount; i++ {
51 if k < n && b.tophash[i] == emptyRest {
52 panic("early emptyRest")
53 }
54 if k >= n && b.tophash[i] != emptyRest {
55 panic("late non-emptyRest")
56 }
57 if k == n-1 && b.tophash[i] == emptyOne {
58 panic("last non-emptyRest entry is emptyOne")
59 }
60 k++
61 }
62 }
63 }
64 }
65
View as plain text