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 func LookupStringConversion1(m map[string]int, bytes []byte) int {
70
71 s := string(bytes)
72 return m[s]
73 }
74 func LookupStringConversion2(m *map[string]int, bytes []byte) int {
75
76 s := string(bytes)
77 return (*m)[s]
78 }
79 func LookupStringConversion3(m map[string]int, bytes []byte) (int, bool) {
80
81 s := string(bytes)
82 r, ok := m[s]
83 return r, ok
84 }
85 func DeleteStringConversion(m map[string]int, bytes []byte) {
86
87 s := string(bytes)
88 delete(m, s)
89 }
90
91
92
93
94
95
96
97 func MapClearReflexive(m map[int]int) {
98
99
100 for k := range m {
101 delete(m, k)
102 }
103 }
104
105 func MapClearIndirect(m map[int]int) {
106 s := struct{ m map[int]int }{m: m}
107
108
109 for k := range s.m {
110 delete(s.m, k)
111 }
112 }
113
114 func MapClearPointer(m map[*byte]int) {
115
116
117 for k := range m {
118 delete(m, k)
119 }
120 }
121
122 func MapClearNotReflexive(m map[float64]int) {
123
124
125 for k := range m {
126 delete(m, k)
127 }
128 }
129
130 func MapClearInterface(m map[interface{}]int) {
131
132
133 for k := range m {
134 delete(m, k)
135 }
136 }
137
138 func MapClearSideEffect(m map[int]int) int {
139 k := 0
140
141
142 for k = range m {
143 delete(m, k)
144 }
145 return k
146 }
147
148 func MapLiteralSizing(x int) (map[int]int, map[int]int) {
149
150
151 m := map[int]int{
152 0: 0,
153 1: 1,
154 2: 2,
155 3: 3,
156 4: 4,
157 5: 5,
158 6: 6,
159 7: 7,
160 8: 8,
161 9: 9,
162 10: 10,
163 11: 11,
164 12: 12,
165 13: 13,
166 14: 14,
167 15: 15,
168 16: 16,
169 17: 17,
170 18: 18,
171 19: 19,
172 20: 20,
173 21: 21,
174 22: 22,
175 23: 23,
176 24: 24,
177 25: 25,
178 26: 26,
179 27: 27,
180 28: 28,
181 29: 29,
182 30: 30,
183 31: 32,
184 32: 32,
185 }
186
187 n := map[int]int{
188 0: 0,
189 1: 1,
190 2: 2,
191 3: 3,
192 4: 4,
193 5: 5,
194 6: 6,
195 7: 7,
196 8: 8,
197 9: 9,
198 10: 10,
199 11: 11,
200 12: 12,
201 13: 13,
202 14: 14,
203 15: 15,
204 16: 16,
205 17: 17,
206 18: 18,
207 19: 19,
208 20: 20,
209 21: 21,
210 22: 22,
211 23: 23,
212 24: 24,
213 25: 25,
214 26: 26,
215 27: 27,
216 28: 28,
217 29: 29,
218 30: 30,
219 31: 32,
220 32: 32,
221 }
222 return m, n
223 }
224
View as plain text