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 func AccessStringIntArray2(m map[string][16]int, k string) bool {
41
42 _, ok := m[k]
43 return ok
44 }
45
46 type Struct struct {
47 A, B, C, D, E, F, G, H, I, J int
48 }
49
50 func AccessStringStruct2(m map[string]Struct, k string) bool {
51
52 _, ok := m[k]
53 return ok
54 }
55
56 func AccessIntArrayLarge2(m map[int][512]int, k int) bool {
57
58 _, ok := m[k]
59 return ok
60 }
61
62
63
64
65
66 func LookupStringConversionSimple(m map[string]int, bytes []byte) int {
67
68 return m[string(bytes)]
69 }
70
71 func LookupStringConversionStructLit(m map[struct{ string }]int, bytes []byte) int {
72
73 return m[struct{ string }{string(bytes)}]
74 }
75
76 func LookupStringConversionArrayLit(m map[[2]string]int, bytes []byte) int {
77
78 return m[[2]string{string(bytes), string(bytes)}]
79 }
80
81 func LookupStringConversionNestedLit(m map[[1]struct{ s [1]string }]int, bytes []byte) int {
82
83 return m[[1]struct{ s [1]string }{struct{ s [1]string }{s: [1]string{string(bytes)}}}]
84 }
85
86 func LookupStringConversionKeyedArrayLit(m map[[2]string]int, bytes []byte) int {
87
88 return m[[2]string{0: string(bytes)}]
89 }
90
91 func LookupStringConversion1(m map[string]int, bytes []byte) int {
92
93 s := string(bytes)
94 return m[s]
95 }
96 func LookupStringConversion2(m *map[string]int, bytes []byte) int {
97
98 s := string(bytes)
99 return (*m)[s]
100 }
101 func LookupStringConversion3(m map[string]int, bytes []byte) (int, bool) {
102
103 s := string(bytes)
104 r, ok := m[s]
105 return r, ok
106 }
107 func DeleteStringConversion(m map[string]int, bytes []byte) {
108
109 s := string(bytes)
110 delete(m, s)
111 }
112
113
114
115
116
117
118
119 func MapClearReflexive(m map[int]int) {
120
121
122 for k := range m {
123 delete(m, k)
124 }
125 }
126
127 func MapClearIndirect(m map[int]int) {
128 s := struct{ m map[int]int }{m: m}
129
130
131 for k := range s.m {
132 delete(s.m, k)
133 }
134 }
135
136 func MapClearPointer(m map[*byte]int) {
137
138
139 for k := range m {
140 delete(m, k)
141 }
142 }
143
144 func MapClearNotReflexive(m map[float64]int) {
145
146
147 for k := range m {
148 delete(m, k)
149 }
150 }
151
152 func MapClearInterface(m map[interface{}]int) {
153
154
155 for k := range m {
156 delete(m, k)
157 }
158 }
159
160 func MapClearSideEffect(m map[int]int) int {
161 k := 0
162
163
164 for k = range m {
165 delete(m, k)
166 }
167 return k
168 }
169
170 func MapLiteralSizing(x int) (map[int]int, map[int]int) {
171
172
173 m := map[int]int{
174 0: 0,
175 1: 1,
176 2: 2,
177 3: 3,
178 4: 4,
179 5: 5,
180 6: 6,
181 7: 7,
182 8: 8,
183 9: 9,
184 10: 10,
185 11: 11,
186 12: 12,
187 13: 13,
188 14: 14,
189 15: 15,
190 16: 16,
191 17: 17,
192 18: 18,
193 19: 19,
194 20: 20,
195 21: 21,
196 22: 22,
197 23: 23,
198 24: 24,
199 25: 25,
200 26: 26,
201 27: 27,
202 28: 28,
203 29: 29,
204 30: 30,
205 31: 32,
206 32: 32,
207 }
208
209 n := map[int]int{
210 0: 0,
211 1: 1,
212 2: 2,
213 3: 3,
214 4: 4,
215 5: 5,
216 6: 6,
217 7: 7,
218 8: 8,
219 9: 9,
220 10: 10,
221 11: 11,
222 12: 12,
223 13: 13,
224 14: 14,
225 15: 15,
226 16: 16,
227 17: 17,
228 18: 18,
229 19: 19,
230 20: 20,
231 21: 21,
232 22: 22,
233 23: 23,
234 24: 24,
235 25: 25,
236 26: 26,
237 27: 27,
238 28: 28,
239 29: 29,
240 30: 30,
241 31: 32,
242 32: 32,
243 }
244 return m, n
245 }
246
View as plain text