mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-03-07 21:27:55 -05:00
ocamlformat
This commit is contained in:
parent
5a50d42352
commit
2827011b37
4 changed files with 13 additions and 12 deletions
|
|
@ -1830,7 +1830,7 @@ module Hash = struct
|
|||
let prime = 0x100000001b3L in
|
||||
let h = ref offset_basis in
|
||||
for k = 0 to 7 do
|
||||
h := Int64.(mul !h prime);
|
||||
(h := Int64.(mul !h prime));
|
||||
h := Int64.(logxor !h (of_int ((n lsr (k * 8)) land 0xff)))
|
||||
done;
|
||||
Int64.to_int !h land max_int
|
||||
|
|
@ -1846,10 +1846,7 @@ module Hash = struct
|
|||
done
|
||||
in
|
||||
B.throughputN 3 ~repeat
|
||||
[
|
||||
"ocaml_fnv", run_ocaml, ();
|
||||
"c_stub", run_c_stub, ();
|
||||
]
|
||||
[ "ocaml_fnv", run_ocaml, (); "c_stub", run_c_stub, () ]
|
||||
|
||||
let () =
|
||||
B.Tree.register ("hash" @>>> [ "int" @>> app_ints bench_hash [ 1_000 ] ])
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ type 'a iter = ('a -> unit) -> unit
|
|||
(* use FNV-1:
|
||||
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function *)
|
||||
external hash : (int[@untagged]) -> (int[@untagged])
|
||||
= "caml_cc_hash_int_byte" "caml_cc_hash_int" [@@noalloc]
|
||||
= "caml_cc_hash_int_byte" "caml_cc_hash_int"
|
||||
[@@noalloc]
|
||||
|
||||
let range i j yield =
|
||||
let rec up i j yield =
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ external hash_to_int64 : (int64[@unboxed]) -> (int64[@unboxed])
|
|||
= "caml_cc_hash_int64_to_int64_byte" "caml_cc_hash_int64_to_int64"
|
||||
|
||||
external hash : (int64[@unboxed]) -> (int[@untagged])
|
||||
= "caml_cc_hash_int64_byte" "caml_cc_hash_int64" [@@noalloc]
|
||||
= "caml_cc_hash_int64_byte" "caml_cc_hash_int64"
|
||||
[@@noalloc]
|
||||
|
||||
(* see {!CCInt.popcount} for more details *)
|
||||
let[@inline] popcount (b : t) : int =
|
||||
|
|
|
|||
|
|
@ -103,8 +103,8 @@ eq' 10 (popcount 0b1110010110110001010L);;
|
|||
eq' 5 (popcount 0b1101110000000000L)
|
||||
|
||||
(* hash tests *)
|
||||
let ( >= ) = Stdlib.( >= );;
|
||||
let ( = ) = Stdlib.( = );;
|
||||
let ( >= ) = Stdlib.( >= )
|
||||
let ( = ) = Stdlib.( = )
|
||||
let ( <> ) = Stdlib.( <> );;
|
||||
|
||||
(* hash is non-negative *)
|
||||
|
|
@ -120,10 +120,12 @@ t @@ fun () -> CCInt64.compare (hash_to_int64 (-1L)) 0L >= 0;;
|
|||
t @@ fun () -> CCInt64.compare (hash_to_int64 min_int) 0L >= 0;;
|
||||
|
||||
(* hash is consistent with hash_to_int64 *)
|
||||
t @@ fun () -> hash 42L = Stdlib.(Int64.to_int (hash_to_int64 42L) land max_int)
|
||||
;;
|
||||
|
||||
t @@ fun () ->
|
||||
hash 42L = Stdlib.(Int64.to_int (hash_to_int64 42L) land max_int);;
|
||||
t @@ fun () ->
|
||||
hash (-1L) = Stdlib.(Int64.to_int (hash_to_int64 (-1L)) land max_int);;
|
||||
hash (-1L) = Stdlib.(Int64.to_int (hash_to_int64 (-1L)) land max_int)
|
||||
;;
|
||||
|
||||
(* different inputs produce different hashes *)
|
||||
t @@ fun () -> hash 0L <> hash 1L;;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue