mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-05 19:00:31 -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 h = ref fnv_offset_basis in
|
||||
for i = 0 to Bytes.length x - 1 do
|
||||
h := Int64.(mul !h fnv_prime);
|
||||
let byte = Char.code (Bytes.unsafe_get x i) in
|
||||
h := Int64.(logxor !h (of_int byte));
|
||||
done;
|
||||
Bytes.iter (fun c ->
|
||||
h := Int64.(mul !h fnv_prime);
|
||||
let byte = Char.code c in
|
||||
h := Int64.(logxor !h (of_int byte));
|
||||
) x;
|
||||
Int64.to_int !h land max_int
|
||||
|
||||
let string (x:string) = bytes (Bytes.unsafe_of_string x)
|
||||
|
||||
(*$T
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue