Expand description
xxHash — extremely fast non-cryptographic hash algorithm.
Provides four variants:
| Struct | Bits | Description |
|---|---|---|
Xxh3_64 | 64 | Recommended — XXH3 algorithm, faster on modern CPUs |
Xxh3_128 | 128 | Recommended — XXH3 algorithm, 128-bit output |
Xxh32 | 32 | Classic xxHash (XXH32) |
Xxh64 | 64 | Classic 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.
- Checksum
Output - Trait for types that can be used as xxHash outputs.