1
2
3
4
5
6
7 package codegen
8
9
10
11
12
13
14
15
16
17
18 func AccessInt1(m map[int]int) int {
19
20 return m[5]
21 }
22
23 func AccessInt2(m map[int]int) bool {
24
25 _, ok := m[5]
26 return ok
27 }
28
29 func AccessString1(m map[string]int) int {
30
31 return m["abc"]
32 }
33
34 func AccessString2(m map[string]int) bool {
35
36 _, ok := m["abc"]
37 return ok
38 }
39
40
41
42
43
44 func LookupStringConversionSimple(m map[string]int, bytes []byte) int {
45
46 return m[string(bytes)]
47 }
48
49 func LookupStringConversionStructLit(m map[struct{ string }]int, bytes []byte) int {
50
51 return m[struct{ string }{string(bytes)}]
52 }
53
54 func LookupStringConversionArrayLit(m map[[2]string]int, bytes []byte) int {
55
56 return m[[2]string{string(bytes), string(bytes)}]
57 }
58
59 func LookupStringConversionNestedLit(m map[[1]struct{ s [1]string }]int, bytes []byte) int {
60
61 return m[[1]struct{ s [1]string }{struct{ s [1]string }{s: [1]string{string(bytes)}}}]
62 }
63
64 func LookupStringConversionKeyedArrayLit(m map[[2]string]int, bytes []byte) int {
65
66 return m[[2]string{0: string(bytes)}]
67 }
68
69
70
71
72
73
74
75 func MapClearReflexive(m map[int]int) {
76
77
78 for k := range m {
79 delete(m, k)
80 }
81 }
82
83 func MapClearIndirect(m map[int]int) {
84 s := struct{ m map[int]int }{m: m}
85
86
87 for k := range s.m {
88 delete(s.m, k)
89 }
90 }
91
92 func MapClearPointer(m map[*byte]int) {
93
94
95 for k := range m {
96 delete(m, k)
97 }
98 }
99
100 func MapClearNotReflexive(m map[float64]int) {
101
102
103 for k := range m {
104 delete(m, k)
105 }
106 }
107
108 func MapClearInterface(m map[interface{}]int) {
109
110
111 for k := range m {
112 delete(m, k)
113 }
114 }
115
116 func MapClearSideEffect(m map[int]int) int {
117 k := 0
118
119
120 for k = range m {
121 delete(m, k)
122 }
123 return k
124 }
125
126 func MapLiteralSizing(x int) (map[int]int, map[int]int) {
127
128 m := map[int]int{
129 0: 0,
130 1: 1,
131 2: 2,
132 3: 3,
133 4: 4,
134 5: 5,
135 6: 6,
136 7: 7,
137 8: 8,
138 9: 9,
139 }
140
141 n := map[int]int{
142 0: x,
143 1: x,
144 2: x,
145 3: x,
146 4: x,
147 5: x,
148 6: x,
149 7: x,
150 8: x,
151 9: x,
152 }
153 return m, n
154 }
155
View as plain text