Skip to main content

Crate xxhash

Crate xxhash 

Source
Expand description

xxHash — extremely fast non-cryptographic hash algorithm.

Provides four variants:

StructBitsDescription
Xxh3_6464Recommended — XXH3 algorithm, faster on modern CPUs
Xxh3_128128Recommended — XXH3 algorithm, 128-bit output
Xxh3232Classic xxHash (XXH32)
Xxh6464Classic xxHash (XXH64)

Prefer Xxh3_64 or Xxh3_128 for new code. XXH3 is the modern variant: ~2x faster on large inputs and >3x faster on small inputs compared to the classic XXH64, with better hash quality.

All types implement the Checksum trait.

§Const one-shot hashing

Use the free functions xxh32, xxh64, xxh3_64, and xxh3_128 for const-compatible one-shot hashing:

use xxhash::xxh3_64;

const HASH: u64 = xxh3_64(b"hello");
assert_eq!(HASH, 0x9555E8555C62DCFD);

§Examples

§One-shot hashing (via trait)

use xxhash::{Xxh3_64, Checksum};

let hash: u64 = Xxh3_64::checksum(b"hello world");

§Incremental hashing

use xxhash::{Xxh3_128, Checksum};

let mut hasher = Xxh3_128::new();
hasher.update(b"hello ");
hasher.update(b"world");
let hash: u128 = hasher.sum();

§Seeded hashing

use xxhash::{Xxh3_64, Checksum};

let mut hasher = Xxh3_64::with_seed(42);
hasher.update(b"data");
let hash: u64 = hasher.sum();

§XXH3 with a custom secret

use xxhash::{Xxh3_64, Checksum};

let secret = [0xAB; 192];
let mut hasher = Xxh3_64::with_secret(secret);
hasher.update(b"data");
let hash: u64 = hasher.sum();

Structs§

Xxh3_64
XXH3 64-bit hash.
Xxh3_128
XXH3 128-bit hash.
Xxh32
XXH32 hash (32-bit).
Xxh64
XXH64 hash (64-bit).

Traits§

Checksum
A trait for computing checksums.
ChecksumOutput
Trait for types that can be used as xxHash outputs.

Functions§

xxh3_64
Compute the XXH3 64-bit hash of data in a single call.
xxh3_128
Compute the XXH3 128-bit hash of data in a single call.
xxh32
Compute the XXH32 hash of data in a single call.
xxh64
Compute the XXH64 hash of data in a single call.