diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-14 15:23:09 -0800 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-14 15:23:09 -0800 |
commit | 66a5bf681def9404a624eba9235d024a104b2602 (patch) | |
tree | 055d871ff4ba92b7077e4534530859d6db41f9ac /py/objset.c | |
parent | 0f59203e37de155c3c7e3fadb35fd3b06cb75478 (diff) | |
parent | f5a0a7d2b30d390f03dd0b6f8866ec619d2c5ee3 (diff) |
Merge pull request #142 from chipaca/containment
Implemented support for `in` and `not in` operators.
Diffstat (limited to 'py/objset.c')
-rw-r--r-- | py/objset.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/py/objset.c b/py/objset.c index e41f2c47f..ba083ada8 100644 --- a/py/objset.c +++ b/py/objset.c @@ -45,6 +45,7 @@ void set_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj print(env, "}"); } + static mp_obj_t set_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args) { switch (n_args) { case 0: @@ -405,6 +406,13 @@ static mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { return set_issuperset(lhs, rhs); case RT_COMPARE_OP_NOT_EQUAL: return MP_BOOL(set_equal(lhs, rhs) == mp_const_false); + case RT_COMPARE_OP_IN: + case RT_COMPARE_OP_NOT_IN: + { + mp_obj_set_t *o = lhs; + mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP); + return MP_BOOL((op == RT_COMPARE_OP_IN) ^ (elem == NULL)); + } default: // op not supported return NULL; |