hash of mpz_t and mpq_t
Marco Bodrato
bodrato at mail.dm.unipi.it
Tue Jun 15 16:44:42 UTC 2021
Ciao,
Il 2021-06-15 14:56 Hans Åberg ha scritto:
> size_t operator()(gmp::integer const& x) const {
> std::size_t h = 0;
> for (int i = 0; i < abs(x.value_->_mp_size); ++i)
> h ^= std::hash<mp_limb_t>()(x.value_->_mp_d[i]);
> return h;
> }
> Possibly, it may not be stable because of calling GMP internals, so
> there might be a point in adding that.
I'd suggest to look at
https://gmplib.org/manual/Integer-Special-Functions ,
looking in particular for mpz_size and mpz_getlimbn ;-) (or even
mpz_limbs_read!)
I'm sure that the same function can be rewritten using only documented
access to the GMP types :-P
You may also look at
https://gmplib.org/manual/C_002b_002b-Interface-General ,
in particular the function mpz_t mpz_class::get_mpz_t (), if you want to
use the mpz_class in C++.
Anyway, the features that different users may ask for a "hash" function
are very different...
Ĝis,
m
More information about the gmp-discuss
mailing list