XXH64 non-cryptographic hash in pure OCaml
README.md

xxhash #

The xxHash non-cryptographic hash in pure OCaml (XXH64).

Some file formats fix the hash function in their specification, so a reader has to compute exactly that one. Apache Parquet's split-block bloom filters hash their values with XXH64 and seed 0. A Bloom filter answers "possibly present" or "definitely absent" for a value by setting k bits chosen by hashes of the value; Parquet's split-block variant uses the top 32 bits of the 64-bit hash to pick one 256-bit block and sets one bit in each of its eight 32-bit words, so a lookup touches one cache line. zstd checksums a frame's content with the low 32 bits of XXH64. xxHash is a family of fast non-cryptographic hashes; this library implements the 64-bit variant, XXH64, in pure OCaml, both in one call and incrementally over data that arrives in pieces. It must not be used where an adversary chooses the input and a collision matters.

Installation #

$ opam install xxhash

If opam cannot find the package, it has not reached the public opam-repository yet. Add the overlay repository first:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install xxhash

Usage #

The digest matches the reference xxhsum -H64:

# Printf.sprintf "%016Lx" (Xxhash.hash64_string "")
- : string = "ef46db3751d8e999"
# Printf.sprintf "%016Lx" (Xxhash.hash64_string "The quick brown fox jumps over the lazy dog")
- : string = "0b242d361fda71bc"

Xxhash.v, Xxhash.update and Xxhash.finalize compute the same digest over data fed in pieces, and Xxhash.copy_state hashes several inputs that share a prefix without hashing the prefix twice.

License #

ISC. See LICENSE.md.