Skip to content

Commit 00d344e

Browse files
committed
fix(Int64.hash): wrong shift
found by @copy
1 parent a3abf40 commit 00d344e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/core/CCInt.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let hash (n : int) : int =
3939
let h = ref offset_basis in
4040
for k = 0 to 7 do
4141
(h := Int64.(mul !h prime));
42-
(* h := h xor (k-th bit of n) *)
42+
(* h := h xor (k-th byte of n) *)
4343
h := Int64.(logxor !h (of_int ((n lsr (k * 8)) land 0xff)))
4444
done;
4545
Int64.to_int !h land max_int

src/core/CCInt64.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ let hash_to_int64 (n : t) =
1616
let h = ref offset_basis in
1717
for k = 0 to 7 do
1818
h := mul !h prime;
19-
(* h := h xor (k-th bit of n) *)
20-
h := logxor !h (logand (shift_left n (k * 8)) 0xffL)
19+
(* h := h xor (k-th byte of n) *)
20+
h := logxor !h (logand (shift_right n (k * 8)) 0xffL)
2121
done;
2222
logand !h max_int
2323

0 commit comments

Comments
 (0)