blob: 05079cf55b08e7cc9d4b5e436e2e6221bd9a4c98 [file] [log] [blame]
Damiend99b0522013-12-21 18:17:45 +00001#include <stdlib.h>
2#include <stdint.h>
John R. Lenton3b0bd872014-01-12 15:56:25 +00003#include <string.h>
Damiend99b0522013-12-21 18:17:45 +00004#include <assert.h>
5
6#include "nlr.h"
7#include "misc.h"
8#include "mpconfig.h"
Damien George55baff42014-01-21 21:40:13 +00009#include "qstr.h"
Damiend99b0522013-12-21 18:17:45 +000010#include "obj.h"
Damien George71c51812014-01-04 20:21:15 +000011#include "runtime.h"
John R. Lentonc1bef212014-01-11 12:39:33 +000012#include "runtime0.h"
Damiend99b0522013-12-21 18:17:45 +000013#include "map.h"
14
15typedef struct _mp_obj_set_t {
16 mp_obj_base_t base;
17 mp_set_t set;
18} mp_obj_set_t;
19
John R. Lenton0ce03b42014-01-12 15:17:42 +000020typedef struct _mp_obj_set_it_t {
21 mp_obj_base_t base;
22 mp_obj_set_t *set;
23 machine_uint_t cur;
24} mp_obj_set_it_t;
25
26static mp_obj_t set_it_iternext(mp_obj_t self_in);
27
Paul Sokolovsky76d982e2014-01-13 19:19:16 +020028void set_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
Damiend99b0522013-12-21 18:17:45 +000029 mp_obj_set_t *self = self_in;
John R. Lenton7244a142014-01-12 23:37:45 +000030 if (self->set.used == 0) {
31 print(env, "set()");
32 return;
33 }
Damiend99b0522013-12-21 18:17:45 +000034 bool first = true;
35 print(env, "{");
36 for (int i = 0; i < self->set.alloc; i++) {
37 if (self->set.table[i] != MP_OBJ_NULL) {
38 if (!first) {
39 print(env, ", ");
40 }
41 first = false;
Paul Sokolovsky76d982e2014-01-13 19:19:16 +020042 mp_obj_print_helper(print, env, self->set.table[i], PRINT_REPR);
Damiend99b0522013-12-21 18:17:45 +000043 }
44 }
45 print(env, "}");
46}
47
John R. Lentonc1bef212014-01-11 12:39:33 +000048
Damien George20006db2014-01-18 14:10:48 +000049static mp_obj_t set_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
50 // TODO check n_kw == 0
51
Damien George71c51812014-01-04 20:21:15 +000052 switch (n_args) {
53 case 0:
54 // return a new, empty set
55 return mp_obj_new_set(0, NULL);
56
57 case 1:
58 {
59 // 1 argument, an iterable from which we make a new set
60 mp_obj_t set = mp_obj_new_set(0, NULL);
61 mp_obj_t iterable = rt_getiter(args[0]);
62 mp_obj_t item;
63 while ((item = rt_iternext(iterable)) != mp_const_stop_iteration) {
64 mp_obj_set_store(set, item);
65 }
66 return set;
67 }
68
69 default:
70 nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_TypeError, "set takes at most 1 argument, %d given", (void*)(machine_int_t)n_args));
71 }
72}
73
John R. Lenton0ce03b42014-01-12 15:17:42 +000074const mp_obj_type_t set_it_type = {
75 { &mp_const_type },
76 "set_iterator",
77 .iternext = set_it_iternext,
78};
79
80static mp_obj_t set_it_iternext(mp_obj_t self_in) {
81 assert(MP_OBJ_IS_TYPE(self_in, &set_it_type));
82 mp_obj_set_it_t *self = self_in;
83 machine_uint_t max = self->set->set.alloc;
84 mp_obj_t *table = self->set->set.table;
85
86 for (machine_uint_t i = self->cur; i < max; i++) {
87 if (table[i] != NULL) {
88 self->cur = i + 1;
89 return table[i];
90 }
91 }
92
93 return mp_const_stop_iteration;
94}
95
96static mp_obj_t set_getiter(mp_obj_t set_in) {
97 mp_obj_set_it_t *o = m_new_obj(mp_obj_set_it_t);
98 o->base.type = &set_it_type;
99 o->set = (mp_obj_set_t *)set_in;
100 o->cur = 0;
101 return o;
102}
103
John R. Lenton19b14d32014-01-12 15:29:11 +0000104
105/******************************************************************************/
106/* set methods */
107
108static mp_obj_t set_add(mp_obj_t self_in, mp_obj_t item) {
109 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
110 mp_obj_set_t *self = self_in;
John R. Lenton2a241722014-01-12 16:39:39 +0000111 mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
John R. Lenton19b14d32014-01-12 15:29:11 +0000112 return mp_const_none;
113}
114static MP_DEFINE_CONST_FUN_OBJ_2(set_add_obj, set_add);
115
John R. Lenton1d7fb2f2014-01-12 15:44:26 +0000116static mp_obj_t set_clear(mp_obj_t self_in) {
117 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
118 mp_obj_set_t *self = self_in;
119
120 mp_set_clear(&self->set);
121
122 return mp_const_none;
123}
124static MP_DEFINE_CONST_FUN_OBJ_1(set_clear_obj, set_clear);
125
John R. Lenton3b0bd872014-01-12 15:56:25 +0000126static mp_obj_t set_copy(mp_obj_t self_in) {
127 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
128 mp_obj_set_t *self = self_in;
129
130 mp_obj_set_t *other = m_new_obj(mp_obj_set_t);
131 other->base.type = &set_type;
John R. Lenton7244a142014-01-12 23:37:45 +0000132 mp_set_init(&other->set, self->set.alloc - 1);
John R. Lenton3b0bd872014-01-12 15:56:25 +0000133 other->set.used = self->set.used;
134 memcpy(other->set.table, self->set.table, self->set.alloc * sizeof(mp_obj_t));
135
136 return other;
137}
138static MP_DEFINE_CONST_FUN_OBJ_1(set_copy_obj, set_copy);
139
John R. Lenton2a241722014-01-12 16:39:39 +0000140static mp_obj_t set_discard(mp_obj_t self_in, mp_obj_t item) {
141 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
142 mp_obj_set_t *self = self_in;
143 mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND);
144 return mp_const_none;
145}
146static MP_DEFINE_CONST_FUN_OBJ_2(set_discard_obj, set_discard);
John R. Lenton19b14d32014-01-12 15:29:11 +0000147
John R. Lenton032129f2014-01-12 17:07:17 +0000148static mp_obj_t set_diff_int(int n_args, const mp_obj_t *args, bool update) {
149 assert(n_args > 0);
150 assert(MP_OBJ_IS_TYPE(args[0], &set_type));
151 mp_obj_set_t *self;
152 if (update) {
153 self = args[0];
154 } else {
155 self = set_copy(args[0]);
156 }
157
158
159 for (int i = 1; i < n_args; i++) {
160 mp_obj_t other = args[i];
161 if (self == other) {
162 set_clear(self);
163 } else {
164 mp_obj_t iter = rt_getiter(other);
165 mp_obj_t next;
166 while ((next = rt_iternext(iter)) != mp_const_stop_iteration) {
167 set_discard(self, next);
168 }
169 }
170 }
171
172 return self;
173}
174
Damien Georgea11ceca2014-01-19 16:02:09 +0000175static mp_obj_t set_diff(uint n_args, const mp_obj_t *args) {
John R. Lenton032129f2014-01-12 17:07:17 +0000176 return set_diff_int(n_args, args, false);
177}
178static MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_obj, 1, set_diff);
179
Damien Georgea11ceca2014-01-19 16:02:09 +0000180static mp_obj_t set_diff_update(uint n_args, const mp_obj_t *args) {
John R. Lenton032129f2014-01-12 17:07:17 +0000181 set_diff_int(n_args, args, true);
182 return mp_const_none;
183}
184static MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_update_obj, 1, set_diff_update);
185
John R. Lentonf1ae6b42014-01-12 17:54:03 +0000186static mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) {
187 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
188 if (self_in == other) {
189 return update ? mp_const_none : set_copy(self_in);
190 }
191
192 mp_obj_set_t *self = self_in;
193 mp_obj_set_t *out = mp_obj_new_set(0, NULL);
194
195 mp_obj_t iter = rt_getiter(other);
196 mp_obj_t next;
197 while ((next = rt_iternext(iter)) != mp_const_stop_iteration) {
198 if (mp_set_lookup(&self->set, next, MP_MAP_LOOKUP)) {
199 set_add(out, next);
200 }
201 }
202
203 if (update) {
204 m_del(mp_obj_t, self->set.table, self->set.alloc);
205 self->set.alloc = out->set.alloc;
206 self->set.used = out->set.used;
207 self->set.table = out->set.table;
208 }
209
210 return update ? mp_const_none : out;
211}
212
213static mp_obj_t set_intersect(mp_obj_t self_in, mp_obj_t other) {
214 return set_intersect_int(self_in, other, false);
215}
216static MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_obj, set_intersect);
217
218static mp_obj_t set_intersect_update(mp_obj_t self_in, mp_obj_t other) {
219 return set_intersect_int(self_in, other, true);
220}
221static MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_update_obj, set_intersect_update);
222
John R. Lenton4a080672014-01-12 18:03:21 +0000223static mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) {
224 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
225 mp_obj_set_t *self = self_in;
226
227 mp_obj_t iter = rt_getiter(other);
228 mp_obj_t next;
229 while ((next = rt_iternext(iter)) != mp_const_stop_iteration) {
230 if (mp_set_lookup(&self->set, next, MP_MAP_LOOKUP)) {
231 return mp_const_false;
232 }
233 }
234 return mp_const_true;
235}
236static MP_DEFINE_CONST_FUN_OBJ_2(set_isdisjoint_obj, set_isdisjoint);
237
John R. Lentonbe790f92014-01-12 23:09:10 +0000238static mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool proper) {
John R. Lentonae00d332014-01-12 18:23:36 +0000239 mp_obj_set_t *self;
240 bool cleanup_self = false;
241 if (MP_OBJ_IS_TYPE(self_in, &set_type)) {
242 self = self_in;
243 } else {
Damien George20006db2014-01-18 14:10:48 +0000244 self = set_make_new((mp_obj_t)&set_type, 1, 0, &self_in);
John R. Lentonae00d332014-01-12 18:23:36 +0000245 cleanup_self = true;
246 }
247
248 mp_obj_set_t *other;
249 bool cleanup_other = false;
250 if (MP_OBJ_IS_TYPE(other_in, &set_type)) {
251 other = other_in;
252 } else {
Damien George20006db2014-01-18 14:10:48 +0000253 other = set_make_new((mp_obj_t)&set_type, 1, 0, &other_in);
John R. Lentonae00d332014-01-12 18:23:36 +0000254 cleanup_other = true;
255 }
John R. Lentonbe790f92014-01-12 23:09:10 +0000256 bool out = true;
257 if (proper && self->set.used == other->set.used) {
258 out = false;
259 } else {
260 mp_obj_t iter = set_getiter(self);
261 mp_obj_t next;
262 while ((next = set_it_iternext(iter)) != mp_const_stop_iteration) {
263 if (!mp_set_lookup(&other->set, next, MP_MAP_LOOKUP)) {
264 out = false;
265 break;
266 }
John R. Lentonae00d332014-01-12 18:23:36 +0000267 }
268 }
269 if (cleanup_self) {
270 set_clear(self);
271 }
272 if (cleanup_other) {
273 set_clear(other);
274 }
John R. Lentonbe790f92014-01-12 23:09:10 +0000275 return MP_BOOL(out);
276}
277static mp_obj_t set_issubset(mp_obj_t self_in, mp_obj_t other_in) {
278 return set_issubset_internal(self_in, other_in, false);
John R. Lentonae00d332014-01-12 18:23:36 +0000279}
280static MP_DEFINE_CONST_FUN_OBJ_2(set_issubset_obj, set_issubset);
281
John R. Lentonbe790f92014-01-12 23:09:10 +0000282static mp_obj_t set_issubset_proper(mp_obj_t self_in, mp_obj_t other_in) {
283 return set_issubset_internal(self_in, other_in, true);
284}
285
John R. Lentonae00d332014-01-12 18:23:36 +0000286static mp_obj_t set_issuperset(mp_obj_t self_in, mp_obj_t other_in) {
John R. Lentonbe790f92014-01-12 23:09:10 +0000287 return set_issubset_internal(other_in, self_in, false);
John R. Lentonae00d332014-01-12 18:23:36 +0000288}
289static MP_DEFINE_CONST_FUN_OBJ_2(set_issuperset_obj, set_issuperset);
290
John R. Lentonbe790f92014-01-12 23:09:10 +0000291static mp_obj_t set_issuperset_proper(mp_obj_t self_in, mp_obj_t other_in) {
292 return set_issubset_internal(other_in, self_in, true);
293}
294
295static mp_obj_t set_equal(mp_obj_t self_in, mp_obj_t other_in) {
296 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
297 mp_obj_set_t *self = self_in;
298 if (!MP_OBJ_IS_TYPE(other_in, &set_type)) {
299 return mp_const_false;
300 }
301 mp_obj_set_t *other = other_in;
302 if (self->set.used != other->set.used) {
303 return mp_const_false;
304 }
305 return set_issubset(self_in, other_in);
306}
307
John R. Lentonae00d332014-01-12 18:23:36 +0000308static mp_obj_t set_pop(mp_obj_t self_in) {
309 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
310 mp_obj_set_t *self = self_in;
311
312 if (self->set.used == 0) {
313 nlr_jump(mp_obj_new_exception_msg(MP_QSTR_KeyError, "pop from an empty set"));
314 }
315 mp_obj_t obj = mp_set_lookup(&self->set, NULL,
316 MP_MAP_LOOKUP_REMOVE_IF_FOUND | MP_MAP_LOOKUP_FIRST);
317 return obj;
318}
319static MP_DEFINE_CONST_FUN_OBJ_1(set_pop_obj, set_pop);
320
321static mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) {
322 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
323 mp_obj_set_t *self = self_in;
324 if (mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND) == MP_OBJ_NULL) {
325 nlr_jump(mp_obj_new_exception(MP_QSTR_KeyError));
326 }
327 return mp_const_none;
328}
329static MP_DEFINE_CONST_FUN_OBJ_2(set_remove_obj, set_remove);
John R. Lenton032129f2014-01-12 17:07:17 +0000330
John R. Lenton0de386b2014-01-12 19:39:48 +0000331static mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other_in) {
332 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
333 mp_obj_set_t *self = self_in;
334 mp_obj_t iter = rt_getiter(other_in);
335 mp_obj_t next;
336 while ((next = rt_iternext(iter)) != mp_const_stop_iteration) {
337 mp_set_lookup(&self->set, next, MP_MAP_LOOKUP_REMOVE_IF_FOUND | MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
338 }
339 return mp_const_none;
340}
341static MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_update_obj, set_symmetric_difference_update);
342
343static mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) {
344 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
345 self_in = set_copy(self_in);
346 set_symmetric_difference_update(self_in, other_in);
347 return self_in;
348}
349static MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_obj, set_symmetric_difference);
350
351static void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) {
352 mp_obj_t iter = rt_getiter(other_in);
353 mp_obj_t next;
354 while ((next = rt_iternext(iter)) != mp_const_stop_iteration) {
355 mp_set_lookup(&self->set, next, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
356 }
357}
358
Damien Georgea11ceca2014-01-19 16:02:09 +0000359static mp_obj_t set_update(uint n_args, const mp_obj_t *args) {
John R. Lenton0de386b2014-01-12 19:39:48 +0000360 assert(n_args > 0);
361 assert(MP_OBJ_IS_TYPE(args[0], &set_type));
362
363 for (int i = 1; i < n_args; i++) {
364 set_update_int(args[0], args[i]);
365 }
366
367 return mp_const_none;
368}
369static MP_DEFINE_CONST_FUN_OBJ_VAR(set_update_obj, 1, set_update);
370
371static mp_obj_t set_union(mp_obj_t self_in, mp_obj_t other_in) {
372 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
373 mp_obj_set_t *self = set_copy(self_in);
374 set_update_int(self, other_in);
375 return self;
376}
377static MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union);
378
379
John R. Lentonbe790f92014-01-12 23:09:10 +0000380static mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
381 mp_obj_t args[] = {lhs, rhs};
382 switch (op) {
383 case RT_BINARY_OP_OR:
384 return set_union(lhs, rhs);
385 case RT_BINARY_OP_XOR:
386 return set_symmetric_difference(lhs, rhs);
387 case RT_BINARY_OP_AND:
388 return set_intersect(lhs, rhs);
389 case RT_BINARY_OP_SUBTRACT:
390 return set_diff(2, args);
391 case RT_BINARY_OP_INPLACE_OR:
392 return set_union(lhs, rhs);
393 case RT_BINARY_OP_INPLACE_XOR:
394 return set_symmetric_difference(lhs, rhs);
395 case RT_BINARY_OP_INPLACE_AND:
396 return set_intersect(lhs, rhs);
397 case RT_BINARY_OP_INPLACE_SUBTRACT:
398 return set_diff(2, args);
Damien George9aa2a522014-02-01 23:04:09 +0000399 case RT_BINARY_OP_LESS:
John R. Lentonbe790f92014-01-12 23:09:10 +0000400 return set_issubset_proper(lhs, rhs);
Damien George9aa2a522014-02-01 23:04:09 +0000401 case RT_BINARY_OP_MORE:
John R. Lentonbe790f92014-01-12 23:09:10 +0000402 return set_issuperset_proper(lhs, rhs);
Damien George9aa2a522014-02-01 23:04:09 +0000403 case RT_BINARY_OP_EQUAL:
John R. Lentonbe790f92014-01-12 23:09:10 +0000404 return set_equal(lhs, rhs);
Damien George9aa2a522014-02-01 23:04:09 +0000405 case RT_BINARY_OP_LESS_EQUAL:
John R. Lentonbe790f92014-01-12 23:09:10 +0000406 return set_issubset(lhs, rhs);
Damien George9aa2a522014-02-01 23:04:09 +0000407 case RT_BINARY_OP_MORE_EQUAL:
John R. Lentonbe790f92014-01-12 23:09:10 +0000408 return set_issuperset(lhs, rhs);
Damien George9aa2a522014-02-01 23:04:09 +0000409 case RT_BINARY_OP_NOT_EQUAL:
John R. Lentonbe790f92014-01-12 23:09:10 +0000410 return MP_BOOL(set_equal(lhs, rhs) == mp_const_false);
Damien George9aa2a522014-02-01 23:04:09 +0000411 case RT_BINARY_OP_IN:
John R. Lenton189c8e12014-01-13 00:52:06 +0000412 {
413 mp_obj_set_t *o = lhs;
414 mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP);
Damien George9aa2a522014-02-01 23:04:09 +0000415 return MP_BOOL(elem != NULL);
John R. Lenton189c8e12014-01-13 00:52:06 +0000416 }
John R. Lentonbe790f92014-01-12 23:09:10 +0000417 default:
418 // op not supported
419 return NULL;
420 }
421}
John R. Lenton0de386b2014-01-12 19:39:48 +0000422
John R. Lenton19b14d32014-01-12 15:29:11 +0000423/******************************************************************************/
424/* set constructors & public C API */
425
426
427static const mp_method_t set_type_methods[] = {
428 { "add", &set_add_obj },
John R. Lenton1d7fb2f2014-01-12 15:44:26 +0000429 { "clear", &set_clear_obj },
John R. Lenton3b0bd872014-01-12 15:56:25 +0000430 { "copy", &set_copy_obj },
John R. Lenton2a241722014-01-12 16:39:39 +0000431 { "discard", &set_discard_obj },
John R. Lenton032129f2014-01-12 17:07:17 +0000432 { "difference", &set_diff_obj },
433 { "difference_update", &set_diff_update_obj },
John R. Lentonf1ae6b42014-01-12 17:54:03 +0000434 { "intersection", &set_intersect_obj },
435 { "intersection_update", &set_intersect_update_obj },
John R. Lenton4a080672014-01-12 18:03:21 +0000436 { "isdisjoint", &set_isdisjoint_obj },
John R. Lentonae00d332014-01-12 18:23:36 +0000437 { "issubset", &set_issubset_obj },
438 { "issuperset", &set_issuperset_obj },
439 { "pop", &set_pop_obj },
440 { "remove", &set_remove_obj },
John R. Lenton0de386b2014-01-12 19:39:48 +0000441 { "symmetric_difference", &set_symmetric_difference_obj },
442 { "symmetric_difference_update", &set_symmetric_difference_update_obj },
443 { "union", &set_union_obj },
444 { "update", &set_update_obj },
John R. Lenton19b14d32014-01-12 15:29:11 +0000445 { NULL, NULL }, // end-of-list sentinel
446};
447
Damien George71c51812014-01-04 20:21:15 +0000448const mp_obj_type_t set_type = {
Damiend99b0522013-12-21 18:17:45 +0000449 { &mp_const_type },
450 "set",
Damien George97209d32014-01-07 15:58:30 +0000451 .print = set_print,
452 .make_new = set_make_new,
John R. Lentonbe790f92014-01-12 23:09:10 +0000453 .binary_op = set_binary_op,
John R. Lenton0ce03b42014-01-12 15:17:42 +0000454 .getiter = set_getiter,
John R. Lenton19b14d32014-01-12 15:29:11 +0000455 .methods = set_type_methods,
Damiend99b0522013-12-21 18:17:45 +0000456};
457
458mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) {
459 mp_obj_set_t *o = m_new_obj(mp_obj_set_t);
460 o->base.type = &set_type;
461 mp_set_init(&o->set, n_args);
462 for (int i = 0; i < n_args; i++) {
John R. Lenton2a241722014-01-12 16:39:39 +0000463 mp_set_lookup(&o->set, items[i], MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
Damiend99b0522013-12-21 18:17:45 +0000464 }
465 return o;
466}
467
468void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) {
469 assert(MP_OBJ_IS_TYPE(self_in, &set_type));
470 mp_obj_set_t *self = self_in;
John R. Lenton2a241722014-01-12 16:39:39 +0000471 mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
Damiend99b0522013-12-21 18:17:45 +0000472}