Use standard hash function for Z.hash and add Z.seeded_hash#150
Use standard hash function for Z.hash and add Z.seeded_hash#150xavierleroy merged 2 commits intoocaml:masterfrom
Z.hash and add Z.seeded_hash#150Conversation
For consistency with other integer types in the standard library (modules Int, Int32, Int64, Nativeint), let's use the standard hash function (`Hashtbl.hash`) for `Z.hash` instead of our variant. This is a bit slower but has several benefits (see ocaml#145): - 32/64 bit compatibility - better mixing of the bits of the result. While we're at it, add a `Z.seeded_hash` function, defined as `Hashtbl.seeded_hash`, so that the `Z` module can be used as the argument to the `Hashtbl.MakeSeeded` functor.
|
Yes, I agree it is better to use the same function for If that's OK with @vouillon as well, we could merge. |
|
Based on the current documentation comment and my vague recollections, I probably thought that the current implementation of I'll merge this PR in a week or so. |
|
@xavierleroy Note that this does not give use 32/64 bit compatibility since small integers are represented as regular OCaml integers when possible. So, an integer that can be represented using 64 bits but not using 32 bits while have a different hash value depending on the architecture. |
|
32 bit/64 bit compatibility is is hard to achieve, see #148 for an example, and less and less of a priority as 32-bit platforms are abandoned one after the other. (Yes, I know JS-of-OCaml is here to stay, but it will soon be the only 32-bit platform that matters.) This said, in this particular case, it might be possible to tweak the hash function attached to type |
For consistency with other integer types in the standard library (modules Int, Int32, Int64, Nativeint), let's use the standard hash function (
Hashtbl.hash) forZ.hashinstead of our variant. This is a bit slower but has several benefits:While we're at it, add a
Z.seeded_hashfunction, defined asHashtbl.seeded_hash, so that theZmodule can be used as the argument to theHashtbl.MakeSeededfunctor.Also: improve documentation of
Z.hashand add some more@sincetags.Closes #145 as this addresses the needs expressed in #145, while being more consistent with the OCaml stdlib modules.