aboutsummaryrefslogtreecommitdiff
path: root/py/objint_longlong.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-07-24 14:21:37 +0100
committerDamien George <damien.p.george@gmail.com>2014-07-24 14:21:37 +0100
commitffe911d228c3b7e35ef6ae775c802cdd05cffa47 (patch)
tree0cb1c7c2e8ef4724a8a8f2c21613e65d88cb69e0 /py/objint_longlong.c
parent4ecb700fe34491c563372ffa72387ef6d45ce5d8 (diff)
py: Make long ints hashable.
Addresses issue #765.
Diffstat (limited to 'py/objint_longlong.c')
-rw-r--r--py/objint_longlong.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/py/objint_longlong.c b/py/objint_longlong.c
index 637d9c32c..466b45c51 100644
--- a/py/objint_longlong.c
+++ b/py/objint_longlong.c
@@ -55,6 +55,16 @@
const mp_obj_int_t mp_maxsize_obj = {{&mp_type_int}, INT_MAX};
#endif
+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;
+ // truncate value to fit in mp_int_t, which gives the same hash as
+ // small int if the value fits without truncation
+ return self->val;
+}
+
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;