summaryrefslogtreecommitdiffstatshomepage
path: root/py/objtuple.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-20 19:20:59 +0000
committerDamien George <damien.p.george@gmail.com>2014-03-20 19:20:59 +0000
commit7f8be591111d9fda9fb52fe1896c8c14f077a9a5 (patch)
tree759d1e186ea420b872935f6f69bc0e5f650d40c8 /py/objtuple.c
parenta925639247d4ec90a93262a280f7ef89ca02ccc9 (diff)
downloadmicropython-7f8be591111d9fda9fb52fe1896c8c14f077a9a5.tar.gz
micropython-7f8be591111d9fda9fb52fe1896c8c14f077a9a5.zip
py: Allow hashing of functions and tuples.
Diffstat (limited to 'py/objtuple.c')
-rw-r--r--py/objtuple.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/py/objtuple.c b/py/objtuple.c
index 83d1f21cea..3378b4ec1c 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -218,6 +218,17 @@ void mp_obj_tuple_del(mp_obj_t self_in) {
m_del_var(mp_obj_tuple_t, mp_obj_t, self->len, self);
}
+machine_int_t mp_obj_tuple_hash(mp_obj_t self_in) {
+ assert(MP_OBJ_IS_TYPE(self_in, &tuple_type));
+ mp_obj_tuple_t *self = self_in;
+ // start hash with pointer to empty tuple, to make it fairly unique
+ machine_int_t hash = (machine_int_t)mp_const_empty_tuple;
+ for (uint i = 0; i < self->len; i++) {
+ hash += mp_obj_hash(self->items[i]);
+ }
+ return hash;
+}
+
/******************************************************************************/
/* tuple iterator */