fix(Int64.hash): wrong shift

found by @copy
This commit is contained in:
Simon Cruanes 2022-08-29 09:49:15 -04:00
parent a3abf40bc2
commit 00d344e09e
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 3 additions and 3 deletions

View file

@ -39,7 +39,7 @@ let hash (n : int) : int =
let h = ref offset_basis in
for k = 0 to 7 do
(h := Int64.(mul !h prime));
(* h := h xor (k-th bit of n) *)
(* h := h xor (k-th byte of n) *)
h := Int64.(logxor !h (of_int ((n lsr (k * 8)) land 0xff)))
done;
Int64.to_int !h land max_int

View file

@ -16,8 +16,8 @@ let hash_to_int64 (n : t) =
let h = ref offset_basis in
for k = 0 to 7 do
h := mul !h prime;
(* h := h xor (k-th bit of n) *)
h := logxor !h (logand (shift_left n (k * 8)) 0xffL)
(* h := h xor (k-th byte of n) *)
h := logxor !h (logand (shift_right n (k * 8)) 0xffL)
done;
logand !h max_int