mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
replace for loop and unsafe_get by using iter
This commit is contained in:
parent
e3b0600a8b
commit
3eb676c55c
1 changed files with 6 additions and 5 deletions
|
|
@ -88,12 +88,13 @@ let nativeint (x:nativeint) = Hashtbl.hash x
|
||||||
|
|
||||||
let bytes (x:bytes) =
|
let bytes (x:bytes) =
|
||||||
let h = ref fnv_offset_basis in
|
let h = ref fnv_offset_basis in
|
||||||
for i = 0 to Bytes.length x - 1 do
|
Bytes.iter (fun c ->
|
||||||
h := Int64.(mul !h fnv_prime);
|
h := Int64.(mul !h fnv_prime);
|
||||||
let byte = Char.code (Bytes.unsafe_get x i) in
|
let byte = Char.code c in
|
||||||
h := Int64.(logxor !h (of_int byte));
|
h := Int64.(logxor !h (of_int byte));
|
||||||
done;
|
) x;
|
||||||
Int64.to_int !h land max_int
|
Int64.to_int !h land max_int
|
||||||
|
|
||||||
let string (x:string) = bytes (Bytes.unsafe_of_string x)
|
let string (x:string) = bytes (Bytes.unsafe_of_string x)
|
||||||
|
|
||||||
(*$T
|
(*$T
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue