field.c, mp.c: Hash `GF' and `FE' objects the same as `MP'.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 15 Oct 2019 10:48:39 +0000 (11:48 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 17 Nov 2019 02:50:40 +0000 (02:50 +0000)
They can be compared for equality, and so they must hash the same way.

field.c
mp.c

diff --git a/field.c b/field.c
index 0a5d908..5b4c27d 100644 (file)
--- a/field.c
+++ b/field.c
@@ -229,15 +229,7 @@ end:
 }
 
 static long fe_pyhash(PyObject *me)
-{
-  size_t sz = FE_F(me)->noctets;
-  uint32 h = 0xe0c127ca + FE_F(me)->ops->ty;
-  octet *p = xmalloc(sz);
-  mp_storeb(FE_X(me), p, sz);
-  h = unihash_hash(&unihash_global, h, p, sz);
-  xfree(p);
-  return (h % LONG_MAX);
-}
+  { return (mphash(FE_X(me))); }
 
 static int fe_pycoerce(PyObject **x, PyObject **y)
 {
diff --git a/mp.c b/mp.c
index 9330121..e4f5980 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -1887,15 +1887,6 @@ end:
   return ((PyObject *)zz);
 }
 
-static long gf_pyhash(PyObject *me)
-{
-  long i = mp_tolong(MP_X(me));
-  i ^= 0xc7ecd67c; /* random perturbance */
-  if (i == -1)
-    i = -2;
-  return (i);
-}
-
 static PyObject *gf_pyexp(PyObject *x, PyObject *y, PyObject *z)
 {
   mp *xx = 0, *yy = 0, *zz = 0;
@@ -2078,7 +2069,7 @@ static PyTypeObject gf_pytype_skel = {
   &gf_pynumber,                                /* @tp_as_number@ */
   0,                                   /* @tp_as_sequence@ */
   0,                                   /* @tp_as_mapping@ */
-  gf_pyhash,                           /* @tp_hash@ */
+  mp_pyhash,                           /* @tp_hash@ */
   0,                                   /* @tp_call@ */
   mp_pyhex,                            /* @tp_str@ */
   0,                                   /* @tp_getattro@ */