Exemplo n.º 1
0
STATIC mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) {
    check_set_or_frozenset(self_in);
    mp_obj_set_t *self_out = set_copy_as_mutable(self_in);
    set_symmetric_difference_update(self_out, other_in);
    self_out->base.type = ((mp_obj_set_t*)self_in)->base.type;
    return self_out;
}
Exemplo n.º 2
0
STATIC mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) {
    assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set));
    self_in = set_copy(self_in);
    set_symmetric_difference_update(self_in, other_in);
    return self_in;
}
Exemplo n.º 3
0
STATIC mp_obj_t set_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
    mp_obj_t args[] = {lhs, rhs};
    #if MICROPY_PY_BUILTINS_FROZENSET
    bool update = MP_OBJ_IS_TYPE(lhs, &mp_type_set);
    #else
    bool update = true;
    #endif
    if (op != MP_BINARY_OP_CONTAINS && !is_set_or_frozenset(rhs)) {
        // For all ops except containment the RHS must be a set/frozenset
        return MP_OBJ_NULL;
    }
    switch (op) {
        case MP_BINARY_OP_OR:
            return set_union(lhs, rhs);
        case MP_BINARY_OP_XOR:
            return set_symmetric_difference(lhs, rhs);
        case MP_BINARY_OP_AND:
            return set_intersect(lhs, rhs);
        case MP_BINARY_OP_SUBTRACT:
            return set_diff(2, args);
        case MP_BINARY_OP_INPLACE_OR:
            if (update) {
                set_update(2, args);
                return lhs;
            } else {
                return set_union(lhs, rhs);
            }
        case MP_BINARY_OP_INPLACE_XOR:
            if (update) {
                set_symmetric_difference_update(lhs, rhs);
                return lhs;
            } else {
                return set_symmetric_difference(lhs, rhs);
            }
        case MP_BINARY_OP_INPLACE_AND:
            rhs = set_intersect_int(lhs, rhs, update);
            if (update) {
                return lhs;
            } else {
                return rhs;
            }
        case MP_BINARY_OP_INPLACE_SUBTRACT:
            return set_diff_int(2, args, update);
        case MP_BINARY_OP_LESS:
            return set_issubset_proper(lhs, rhs);
        case MP_BINARY_OP_MORE:
            return set_issuperset_proper(lhs, rhs);
        case MP_BINARY_OP_EQUAL:
            return set_equal(lhs, rhs);
        case MP_BINARY_OP_LESS_EQUAL:
            return set_issubset(lhs, rhs);
        case MP_BINARY_OP_MORE_EQUAL:
            return set_issuperset(lhs, rhs);
        case MP_BINARY_OP_CONTAINS: {
            mp_obj_set_t *o = MP_OBJ_TO_PTR(lhs);
            mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP);
            return mp_obj_new_bool(elem != MP_OBJ_NULL);
        }
        default:
            return MP_OBJ_NULL; // op not supported
    }
}
Exemplo n.º 4
0
STATIC mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) {
    mp_obj_t self_out = set_copy(self_in);
    set_symmetric_difference_update(self_out, other_in);
    return self_out;
}