hash of mpz_t and mpq_t

Marc Glisse marc.glisse at inria.fr
Wed Jun 16 19:58:48 UTC 2021

On Tue, 15 Jun 2021, Hans Åberg wrote:

> GMP C++ has several issues: requires a special compile,

Are you referring to the lack of support for visual studio?

> very complicated templates,

doesn't seem very relevant to a user, while performance is.

> and move operators implemented using swap.

What's wrong with a move assignment using swap? (move construction 
does not use swap)

Maybe you would prefer if it released the memory of the moved-from object 
immediately? That's a trade-off, releasing memory early is nice, but 
keeping the memory may save the need for an allocation.

> The C++ standard comes with hash functions

The C++ standard still doesn't provide a function to hash a pair of int. 
They are currently discussing again what a good hashing facility should 
look like, including how to use a seed, and without restricting the size 
of the state/seed to size_t.

> for use with its containers std::unordered_map etc, which is was asked 
> for. Typically, one wants something fast here.

There we agree that std::hash is meant for use in hash maps, and should 
not be used for cryptographic purposes.

I think I'd be in favor of a mpz_hash(mpz_t, seed) as described by Mathieu 
(I have requested similar things in the past 
with suitable documentation, but I am leaving that to more knowledgeable 

Marc Glisse

More information about the gmp-discuss mailing list