package b0

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module B0_hashSource

Hash values and functions.

The property we want from these functions is speed and collision resistance. Build correctness depends on the latter.

Hash values

Sourcetype t

The type for hash values. All hash functions use this representation. It is not possible to distinguish them, except for their length which might vary, or not.

Sourceval nil : t

nil is the only hash value of length 0.

Sourceval length : t -> int

length h is the length of h in bytes.

Predicate and comparisons

Sourceval is_nil : t -> bool

is_nil h is true iff h is nil.

Sourceval equal : t -> t -> bool

equal h0 h1 is true iff h0 and h1 are equal.

Sourceval compare : t -> t -> int

compare h0 h1 is a total order on hashes compatible with equal.

Converting

Sourceval to_binary_string : t -> string

to_binary_string h is the sequence of bytes of h.

Sourceval of_binary_string : string -> t

of_binary_string s is the sequences of bytes of s as a hash value.

Sourceval to_hex : t -> string

to_hex h is String.Ascii.to_hex (to_bytes h).

Sourceval of_hex : string -> (t, string) result

of_hex s is Result.map of_binary_string (String.Ascii.of_hex s).

Sourceval of_hex' : string -> (t, int) result

of_hex s is Result.map of_binary_string (String.Ascii.of_hex' s).

pp formats using to_hex or, if the hash is nil, formats "nil".

Hash functions

Sourcemodule type T = sig ... end

The type for hash functions.

Sourcemodule Xxh3_64 : T

Xxh3_64 is the xxHash3 64-bit hash.

Sourcemodule Xxh3_128 : T

Xxh3_128 is the xxHash3 128-bit hash.

Sourceval funs : unit -> (module T) list

funs () is the list of available hash functions.

Sourceval add_fun : (module T) -> unit

add_fun m adds m to the list returned by funs.

Sourceval get_fun : string -> ((module T), string) result

get_fun id is the hash function with identifier id or an error message.