summaryrefslogtreecommitdiffstatshomepage
path: root/py/objset.c
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-12 15:29:11 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-12 15:29:11 +0000
commit19b14d3d8ae229f17f8b63825f96220db37e3770 (patch)
tree2cb336aa5cc22c853e53cf99047ca5245b3ecb74 /py/objset.c
parent0ce03b48a04a7766f8694b1de8a88073542dcc20 (diff)
downloadmicropython-19b14d3d8ae229f17f8b63825f96220db37e3770.tar.gz
micropython-19b14d3d8ae229f17f8b63825f96220db37e3770.zip
Implemented set.add
Diffstat (limited to 'py/objset.c')
-rw-r--r--py/objset.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/py/objset.c b/py/objset.c
index 5606c47516..a74d1eb6a3 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -92,12 +92,35 @@ static mp_obj_t set_getiter(mp_obj_t set_in) {
return o;
}
+
+/******************************************************************************/
+/* set methods */
+
+static mp_obj_t set_add(mp_obj_t self_in, mp_obj_t item) {
+ assert(MP_OBJ_IS_TYPE(self_in, &set_type));
+ mp_obj_set_t *self = self_in;
+ mp_set_lookup(&self->set, item, true);
+ return mp_const_none;
+}
+static MP_DEFINE_CONST_FUN_OBJ_2(set_add_obj, set_add);
+
+
+/******************************************************************************/
+/* set constructors & public C API */
+
+
+static const mp_method_t set_type_methods[] = {
+ { "add", &set_add_obj },
+ { NULL, NULL }, // end-of-list sentinel
+};
+
const mp_obj_type_t set_type = {
{ &mp_const_type },
"set",
.print = set_print,
.make_new = set_make_new,
.getiter = set_getiter,
+ .methods = set_type_methods,
};
mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) {