diff --git a/src/xxhash/containers_xxhash.ml b/src/xxhash/containers_xxhash.ml index b30a8323..5b458f04 100644 --- a/src/xxhash/containers_xxhash.ml +++ b/src/xxhash/containers_xxhash.ml @@ -1,20 +1,32 @@ -external hash_string : string -> (int64[@unboxed]) -> (int64[@unboxed]) - = "caml_cc_xxhash_string_byte" "caml_cc_xxhash_string" -[@@noalloc] +module Raw = struct + external hash_string : string -> (int64[@unboxed]) -> (int64[@unboxed]) + = "caml_cc_xxhash_string_byte" "caml_cc_xxhash_string" + [@@noalloc] -external hash_int64 : - (int64[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed]) - = "caml_cc_xxhash_int64_byte" "caml_cc_xxhash_int64" -[@@noalloc] + external hash_int64 : + (int64[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed]) + = "caml_cc_xxhash_int64_byte" "caml_cc_xxhash_int64" + [@@noalloc] -external hash_int32 : - (int32[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed]) - = "caml_cc_xxhash_int32_byte" "caml_cc_xxhash_int32" -[@@noalloc] + external hash_int32 : + (int32[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed]) + = "caml_cc_xxhash_int32_byte" "caml_cc_xxhash_int32" + [@@noalloc] -external hash_int : (int[@untagged]) -> (int64[@unboxed]) -> (int64[@unboxed]) - = "caml_cc_xxhash_int_byte" "caml_cc_xxhash_int" -[@@noalloc] + external hash_int : (int[@untagged]) -> (int64[@unboxed]) -> (int64[@unboxed]) + = "caml_cc_xxhash_int_byte" "caml_cc_xxhash_int" + [@@noalloc] +end -let[@inline] hash_bool b seed = hash_int (Bool.to_int b) seed -let[@inline] hash_char c seed = hash_int (Char.code c) seed +let[@inline] hash_string s = Raw.hash_string s 0L +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 diff --git a/src/xxhash/containers_xxhash.mli b/src/xxhash/containers_xxhash.mli index b9bb1658..6747c741 100644 --- a/src/xxhash/containers_xxhash.mli +++ b/src/xxhash/containers_xxhash.mli @@ -6,31 +6,64 @@ All functions use XXH64 and are noalloc in native code. *) -external hash_string : string -> (int64[@unboxed]) -> (int64[@unboxed]) - = "caml_cc_xxhash_string_byte" "caml_cc_xxhash_string" -[@@noalloc] -(** [hash_string s seed] hashes [s] with [seed] using XXH64. *) +(** Raw bindings with explicit seed argument. *) +module Raw : sig + external hash_string : string -> (int64[@unboxed]) -> (int64[@unboxed]) + = "caml_cc_xxhash_string_byte" "caml_cc_xxhash_string" + [@@noalloc] + (** [hash_string s seed] hashes [s] with [seed] using XXH64. *) -external hash_int64 : - (int64[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed]) - = "caml_cc_xxhash_int64_byte" "caml_cc_xxhash_int64" -[@@noalloc] -(** [hash_int64 v seed] hashes the 8-byte representation of [v] with [seed]. *) + external hash_int64 : + (int64[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed]) + = "caml_cc_xxhash_int64_byte" "caml_cc_xxhash_int64" + [@@noalloc] + (** [hash_int64 v seed] hashes the 8-byte representation of [v] with [seed]. *) -external hash_int32 : - (int32[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed]) - = "caml_cc_xxhash_int32_byte" "caml_cc_xxhash_int32" -[@@noalloc] -(** [hash_int32 v seed] hashes the 4-byte representation of [v] with [seed]. *) + external hash_int32 : + (int32[@unboxed]) -> (int64[@unboxed]) -> (int64[@unboxed]) + = "caml_cc_xxhash_int32_byte" "caml_cc_xxhash_int32" + [@@noalloc] + (** [hash_int32 v seed] hashes the 4-byte representation of [v] with [seed]. *) -external hash_int : (int[@untagged]) -> (int64[@unboxed]) -> (int64[@unboxed]) - = "caml_cc_xxhash_int_byte" "caml_cc_xxhash_int" -[@@noalloc] -(** [hash_int v seed] hashes [v] as a 64-bit integer with [seed]. - Noalloc and untagged in native code. *) + external hash_int : (int[@untagged]) -> (int64[@unboxed]) -> (int64[@unboxed]) + = "caml_cc_xxhash_int_byte" "caml_cc_xxhash_int" + [@@noalloc] + (** [hash_int v seed] hashes [v] as a 64-bit integer with [seed]. Noalloc + and untagged in native code. *) +end -val hash_bool : bool -> int64 -> int64 -(** [hash_bool b seed] hashes [b] as an integer (0 or 1) with [seed]. *) +val hash_string : string -> int64 +(** [hash_string s] hashes [s] using XXH64 with seed [0L]. *) -val hash_char : char -> int64 -> int64 -(** [hash_char c seed] hashes [c] as its character code with [seed]. *) +val hash_string_seed : string -> int64 -> int64 +(** [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. *)