Source file
src/runtime/map_swiss_test.go
1
2
3
4
5
6
7 package runtime_test
8
9 import (
10 "internal/abi"
11 "internal/goarch"
12 "internal/runtime/maps"
13 "slices"
14 "testing"
15 "unsafe"
16 )
17
18 func TestHmapSize(t *testing.T) {
19
20
21
22 wantSize := uintptr(2*8 + 4*goarch.PtrSize)
23 gotSize := unsafe.Sizeof(maps.Map{})
24 if gotSize != wantSize {
25 t.Errorf("sizeof(maps.Map{})==%d, want %d", gotSize, wantSize)
26 }
27 }
28
29
30 func TestGroupSizeZero(t *testing.T) {
31 var m map[struct{}]struct{}
32 mTyp := abi.TypeOf(m)
33 mt := (*abi.SwissMapType)(unsafe.Pointer(mTyp))
34
35
36
37
38
39 if mt.Group.Size() <= 8 {
40 t.Errorf("Group size got %d want >8", mt.Group.Size())
41 }
42 }
43
44 func TestMapIterOrder(t *testing.T) {
45 sizes := []int{3, 7, 9, 15}
46 for _, n := range sizes {
47 for i := 0; i < 1000; i++ {
48
49 m := make(map[int]bool)
50 for i := 0; i < n; i++ {
51 m[i] = true
52 }
53
54 ord := func() []int {
55 var s []int
56 for key := range m {
57 s = append(s, key)
58 }
59 return s
60 }
61 first := ord()
62 ok := false
63 for try := 0; try < 100; try++ {
64 if !slices.Equal(first, ord()) {
65 ok = true
66 break
67 }
68 }
69 if !ok {
70 t.Errorf("Map with n=%d elements had consistent iteration order: %v", n, first)
71 break
72 }
73 }
74 }
75 }
76
View as plain text