mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-05-05 08:54:22 -04:00
nicer API with and without seed
This commit is contained in:
parent
a3c061a388
commit
9865a26c91
2 changed files with 84 additions and 39 deletions
|
|
@ -1,20 +1,32 @@
|
||||||
external hash_string : string -> (int64[@unboxed]) -> (int64[@unboxed])
|
module Raw = struct
|
||||||
= "caml_cc_xxhash_string_byte" "caml_cc_xxhash_string"
|
external hash_string : string -> (int64[@unboxed]) -> (int64[@unboxed])
|
||||||
[@@noalloc]
|
= "caml_cc_xxhash_string_byte" "caml_cc_xxhash_string"
|
||||||
|
[@@noalloc]
|
||||||
|
|
||||||
external hash_int64 :
|
external hash_int64 :
|
||||||
(int64[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
(int64[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
||||||
= "caml_cc_xxhash_int64_byte" "caml_cc_xxhash_int64"
|
= "caml_cc_xxhash_int64_byte" "caml_cc_xxhash_int64"
|
||||||
[@@noalloc]
|
[@@noalloc]
|
||||||
|
|
||||||
external hash_int32 :
|
external hash_int32 :
|
||||||
(int32[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
(int32[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
||||||
= "caml_cc_xxhash_int32_byte" "caml_cc_xxhash_int32"
|
= "caml_cc_xxhash_int32_byte" "caml_cc_xxhash_int32"
|
||||||
[@@noalloc]
|
[@@noalloc]
|
||||||
|
|
||||||
external hash_int : (int[@untagged]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
external hash_int : (int[@untagged]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
||||||
= "caml_cc_xxhash_int_byte" "caml_cc_xxhash_int"
|
= "caml_cc_xxhash_int_byte" "caml_cc_xxhash_int"
|
||||||
[@@noalloc]
|
[@@noalloc]
|
||||||
|
end
|
||||||
|
|
||||||
let[@inline] hash_bool b seed = hash_int (Bool.to_int b) seed
|
let[@inline] hash_string s = Raw.hash_string s 0L
|
||||||
let[@inline] hash_char c seed = hash_int (Char.code c) seed
|
let[@inline] hash_string_seed s seed = Raw.hash_string s seed
|
||||||
|
let[@inline] hash_int64 v = Raw.hash_int64 v 0L
|
||||||
|
let[@inline] hash_int64_seed v seed = Raw.hash_int64 v seed
|
||||||
|
let[@inline] hash_int32 v = Raw.hash_int32 v 0L
|
||||||
|
let[@inline] hash_int32_seed v seed = Raw.hash_int32 v seed
|
||||||
|
let[@inline] hash_int v = Raw.hash_int v 0L
|
||||||
|
let[@inline] hash_int_seed v seed = Raw.hash_int v seed
|
||||||
|
let[@inline] hash_bool b = Raw.hash_int (Bool.to_int b) 0L
|
||||||
|
let[@inline] hash_bool_seed b seed = Raw.hash_int (Bool.to_int b) seed
|
||||||
|
let[@inline] hash_char c = Raw.hash_int (Char.code c) 0L
|
||||||
|
let[@inline] hash_char_seed c seed = Raw.hash_int (Char.code c) seed
|
||||||
|
|
|
||||||
|
|
@ -6,31 +6,64 @@
|
||||||
All functions use XXH64 and are noalloc in native code.
|
All functions use XXH64 and are noalloc in native code.
|
||||||
*)
|
*)
|
||||||
|
|
||||||
external hash_string : string -> (int64[@unboxed]) -> (int64[@unboxed])
|
(** Raw bindings with explicit seed argument. *)
|
||||||
= "caml_cc_xxhash_string_byte" "caml_cc_xxhash_string"
|
module Raw : sig
|
||||||
[@@noalloc]
|
external hash_string : string -> (int64[@unboxed]) -> (int64[@unboxed])
|
||||||
(** [hash_string s seed] hashes [s] with [seed] using XXH64. *)
|
= "caml_cc_xxhash_string_byte" "caml_cc_xxhash_string"
|
||||||
|
[@@noalloc]
|
||||||
|
(** [hash_string s seed] hashes [s] with [seed] using XXH64. *)
|
||||||
|
|
||||||
external hash_int64 :
|
external hash_int64 :
|
||||||
(int64[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
(int64[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
||||||
= "caml_cc_xxhash_int64_byte" "caml_cc_xxhash_int64"
|
= "caml_cc_xxhash_int64_byte" "caml_cc_xxhash_int64"
|
||||||
[@@noalloc]
|
[@@noalloc]
|
||||||
(** [hash_int64 v seed] hashes the 8-byte representation of [v] with [seed]. *)
|
(** [hash_int64 v seed] hashes the 8-byte representation of [v] with [seed]. *)
|
||||||
|
|
||||||
external hash_int32 :
|
external hash_int32 :
|
||||||
(int32[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
(int32[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
||||||
= "caml_cc_xxhash_int32_byte" "caml_cc_xxhash_int32"
|
= "caml_cc_xxhash_int32_byte" "caml_cc_xxhash_int32"
|
||||||
[@@noalloc]
|
[@@noalloc]
|
||||||
(** [hash_int32 v seed] hashes the 4-byte representation of [v] with [seed]. *)
|
(** [hash_int32 v seed] hashes the 4-byte representation of [v] with [seed]. *)
|
||||||
|
|
||||||
external hash_int : (int[@untagged]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
external hash_int : (int[@untagged]) -> (int64[@unboxed]) -> (int64[@unboxed])
|
||||||
= "caml_cc_xxhash_int_byte" "caml_cc_xxhash_int"
|
= "caml_cc_xxhash_int_byte" "caml_cc_xxhash_int"
|
||||||
[@@noalloc]
|
[@@noalloc]
|
||||||
(** [hash_int v seed] hashes [v] as a 64-bit integer with [seed].
|
(** [hash_int v seed] hashes [v] as a 64-bit integer with [seed]. Noalloc
|
||||||
Noalloc and untagged in native code. *)
|
and untagged in native code. *)
|
||||||
|
end
|
||||||
|
|
||||||
val hash_bool : bool -> int64 -> int64
|
val hash_string : string -> int64
|
||||||
(** [hash_bool b seed] hashes [b] as an integer (0 or 1) with [seed]. *)
|
(** [hash_string s] hashes [s] using XXH64 with seed [0L]. *)
|
||||||
|
|
||||||
val hash_char : char -> int64 -> int64
|
val hash_string_seed : string -> int64 -> int64
|
||||||
(** [hash_char c seed] hashes [c] as its character code with [seed]. *)
|
(** [hash_string_seed s seed] hashes [s] with an explicit seed. *)
|
||||||
|
|
||||||
|
val hash_int64 : int64 -> int64
|
||||||
|
(** [hash_int64 v] hashes the 8-byte representation of [v] with seed [0L]. *)
|
||||||
|
|
||||||
|
val hash_int64_seed : int64 -> int64 -> int64
|
||||||
|
(** [hash_int64_seed v seed] hashes [v] with an explicit seed. *)
|
||||||
|
|
||||||
|
val hash_int32 : int32 -> int64
|
||||||
|
(** [hash_int32 v] hashes the 4-byte representation of [v] with seed [0L]. *)
|
||||||
|
|
||||||
|
val hash_int32_seed : int32 -> int64 -> int64
|
||||||
|
(** [hash_int32_seed v seed] hashes [v] with an explicit seed. *)
|
||||||
|
|
||||||
|
val hash_int : int -> int64
|
||||||
|
(** [hash_int v] hashes [v] as a 64-bit integer with seed [0L]. *)
|
||||||
|
|
||||||
|
val hash_int_seed : int -> int64 -> int64
|
||||||
|
(** [hash_int_seed v seed] hashes [v] with an explicit seed. *)
|
||||||
|
|
||||||
|
val hash_bool : bool -> int64
|
||||||
|
(** [hash_bool b] hashes [b] as an integer (0 or 1) with seed [0L]. *)
|
||||||
|
|
||||||
|
val hash_bool_seed : bool -> int64 -> int64
|
||||||
|
(** [hash_bool_seed b seed] hashes [b] with an explicit seed. *)
|
||||||
|
|
||||||
|
val hash_char : char -> int64
|
||||||
|
(** [hash_char c] hashes [c] as its character code with seed [0L]. *)
|
||||||
|
|
||||||
|
val hash_char_seed : char -> int64 -> int64
|
||||||
|
(** [hash_char_seed c seed] hashes [c] with an explicit seed. *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue