mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
fix(Int64.hash): wrong shift
found by @copy
This commit is contained in:
parent
a3abf40bc2
commit
00d344e09e
2 changed files with 3 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue