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
129 m := map[int]int{
130 0: 0,
131 1: 1,
132 2: 2,
133 3: 3,
134 4: 4,
135 5: 5,
136 6: 6,
137 7: 7,
138 8: 8,
139 9: 9,
140 10: 10,
141 11: 11,
142 12: 12,
143 13: 13,
144 14: 14,
145 15: 15,
146 16: 16,
147 17: 17,
148 18: 18,
149 19: 19,
150 20: 20,
151 21: 21,
152 22: 22,
153 23: 23,
154 24: 24,
155 25: 25,
156 26: 26,
157 27: 27,
158 28: 28,
159 29: 29,
160 30: 30,
161 31: 32,
162 32: 32,
163 }
164
165 n := map[int]int{
166 0: 0,
167 1: 1,
168 2: 2,
169 3: 3,
170 4: 4,
171 5: 5,
172 6: 6,
173 7: 7,
174 8: 8,
175 9: 9,
176 10: 10,
177 11: 11,
178 12: 12,
179 13: 13,
180 14: 14,
181 15: 15,
182 16: 16,
183 17: 17,
184 18: 18,
185 19: 19,
186 20: 20,
187 21: 21,
188 22: 22,
189 23: 23,
190 24: 24,
191 25: 25,
192 26: 26,
193 27: 27,
194 28: 28,
195 29: 29,
196 30: 30,
197 31: 32,
198 32: 32,
199 }
200 return m, n
201 }
202
View as plain text