34 #if MICROPY_PY_BUILTINS_SET 36 typedef struct _mp_obj_set_t {
41 typedef struct _mp_obj_set_it_t {
52 #if MICROPY_PY_BUILTINS_FROZENSET 59 #define check_set(o) mp_check_self(MP_OBJ_IS_TYPE(o, &mp_type_set)) 63 #define check_set_or_frozenset(o) mp_check_self(is_set_or_frozenset(o)) 68 #if MICROPY_PY_BUILTINS_FROZENSET 71 if (self->set.used == 0) {
72 #if MICROPY_PY_BUILTINS_FROZENSET 81 #if MICROPY_PY_BUILTINS_FROZENSET 87 for (
size_t i = 0; i <
self->set.alloc; i++) {
88 if (MP_SET_SLOT_IS_FILLED(&self->set, i)) {
97 #if MICROPY_PY_BUILTINS_FROZENSET 112 set->base.type = type;
134 size_t max =
self->set->set.alloc;
137 for (
size_t i = self->cur; i < max; i++) {
138 if (MP_SET_SLOT_IS_FILLED(
set, i)) {
140 return set->
table[i];
149 mp_obj_set_it_t *o = (mp_obj_set_it_t*)iter_buf;
180 check_set_or_frozenset(self_in);
182 mp_obj_set_t *other =
m_new_obj(mp_obj_set_t);
183 other->base.type =
self->base.type;
185 other->set.used =
self->set.used;
186 memcpy(other->set.table, self->set.table, self->set.alloc *
sizeof(
mp_obj_t));
205 self = set_copy(
args[0]);
208 for (
size_t i = 1; i < n_args; i++) {
226 return set_diff_int(n_args,
args,
false);
231 set_diff_int(n_args,
args,
true);
240 check_set_or_frozenset(self_in);
243 if (self_in == other) {
260 self->set.alloc = out->set.alloc;
261 self->set.used = out->set.used;
262 self->set.table = out->set.table;
269 return set_intersect_int(self_in, other,
false);
274 return set_intersect_int(self_in, other,
true);
279 check_set_or_frozenset(self_in);
296 bool cleanup_self =
false;
297 if (is_set_or_frozenset(self_in)) {
305 bool cleanup_other =
false;
306 if (is_set_or_frozenset(other_in)) {
310 cleanup_other =
true;
313 if (proper && self->set.used == other->set.used) {
336 return set_issubset_internal(self_in, other_in,
false);
341 return set_issubset_internal(self_in, other_in,
true);
345 return set_issubset_internal(other_in, self_in,
false);
350 return set_issubset_internal(other_in, self_in,
true);
354 check_set_or_frozenset(self_in);
356 if (!is_set_or_frozenset(other_in)) {
360 if (self->set.used != other->set.used) {
363 return set_issubset(self_in, other_in);
388 check_set_or_frozenset(self_in);
400 mp_obj_t self_out = set_copy(self_in);
401 set_symmetric_difference_update(self_out, other_in);
406 STATIC void set_update_int(mp_obj_set_t *
self,
mp_obj_t other_in) {
416 for (
size_t i = 1; i < n_args; i++) {
425 check_set_or_frozenset(self_in);
437 #if MICROPY_PY_BUILTINS_FROZENSET 442 size_t max =
self->set.alloc;
445 for (
size_t i = 0; i < max; i++) {
446 if (MP_SET_SLOT_IS_FILLED(
set, i)) {
459 #if MICROPY_PY_BUILTINS_FROZENSET 470 return set_union(lhs, rhs);
472 return set_symmetric_difference(lhs, rhs);
474 return set_intersect(lhs, rhs);
476 return set_diff(2,
args);
482 return set_union(lhs, rhs);
486 set_symmetric_difference_update(lhs, rhs);
489 return set_symmetric_difference(lhs, rhs);
492 rhs = set_intersect_int(lhs, rhs, update);
499 return set_diff_int(2,
args, update);
501 return set_issubset_proper(lhs, rhs);
503 return set_issuperset_proper(lhs, rhs);
505 return set_equal(lhs, rhs);
507 return set_issubset(lhs, rhs);
509 return set_issuperset(lhs, rhs);
539 {
MP_ROM_QSTR(MP_QSTR_symmetric_difference_update),
MP_ROM_PTR(&set_symmetric_difference_update_obj) },
551 .make_new = set_make_new,
552 .unary_op = set_unary_op,
553 .binary_op = set_binary_op,
554 .getiter = set_getiter,
558 #if MICROPY_PY_BUILTINS_FROZENSET 574 .
name = MP_QSTR_frozenset,
576 .make_new = set_make_new,
577 .unary_op = set_unary_op,
578 .binary_op = set_binary_op,
579 .getiter = set_getiter,
585 mp_obj_set_t *o =
m_new_obj(mp_obj_set_t);
588 for (
size_t i = 0; i < n_args; i++) {
600 #endif // MICROPY_PY_BUILTINS_SET
mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg)
const mp_obj_type_t mp_type_set
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
#define MP_DEFINE_CONST_DICT(dict_name, table_name)
#define MP_OBJ_IS_TYPE(o, t)
#define m_del(type, ptr, num)
int mp_print_str(const mp_print_t *print, const char *str)
#define MP_OBJ_FROM_PTR(p)
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
#define MP_OBJ_SMALL_INT_VALUE(o)
mp_obj_t(* mp_fun_1_t)(mp_obj_t)
void mp_set_init(mp_set_t *set, size_t n)
#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name)
#define MP_OBJ_NEW_SMALL_INT(small_int)
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item)
mp_obj_t mp_set_remove_first(mp_set_t *set)
const mp_obj_type_t mp_type_polymorph_iter
mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg)
#define mp_check_self(pred)
const mp_obj_type_t mp_type_frozenset
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind)
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items)
const mp_obj_type_t mp_type_type
#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name)
void mp_set_clear(mp_set_t *set)
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__)
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf)
#define MP_OBJ_STOP_ITERATION
mp_obj_t mp_iternext(mp_obj_t o_in)
const mp_obj_type_t mp_type_KeyError
void * memcpy(void *dst, const void *src, size_t n)