diff options
| author | Damien George <damien.p.george@gmail.com> | 2014-07-24 14:21:37 +0100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2014-07-24 14:21:37 +0100 |
| commit | ffe911d228c3b7e35ef6ae775c802cdd05cffa47 (patch) | |
| tree | 0cb1c7c2e8ef4724a8a8f2c21613e65d88cb69e0 /py/objint_mpz.c | |
| parent | 4ecb700fe34491c563372ffa72387ef6d45ce5d8 (diff) | |
py: Make long ints hashable.
Addresses issue #765.
Diffstat (limited to 'py/objint_mpz.c')
| -rw-r--r-- | py/objint_mpz.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 6e1c3c5a8..c60e5c2b8 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -96,6 +96,14 @@ char *mp_obj_int_formatted_impl(char **buf, int *buf_size, int *fmt_size, mp_con return str; } +mp_int_t mp_obj_int_hash(mp_obj_t self_in) { + if (MP_OBJ_IS_SMALL_INT(self_in)) { + return MP_OBJ_SMALL_INT_VALUE(self_in); + } + mp_obj_int_t *self = self_in; + return mpz_hash(&self->mpz); +} + bool mp_obj_int_is_positive(mp_obj_t self_in) { if (MP_OBJ_IS_SMALL_INT(self_in)) { return MP_OBJ_SMALL_INT_VALUE(self_in) >= 0; |
