A Rust implementation of the XXHash and XXH3 algorithms
  • Rust 95.9%
  • R 3.1%
  • Shell 0.7%
  • jq 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jake Goulding 2d5963bad1
Some checks failed
Continuous integration / library (macos-latest, stable) (push) Has been cancelled
Continuous integration / library (ubuntu-latest, 1.81.0) (push) Has been cancelled
Continuous integration / library (ubuntu-latest, beta) (push) Has been cancelled
Continuous integration / library (ubuntu-latest, nightly) (push) Has been cancelled
Continuous integration / library (ubuntu-latest, stable) (push) Has been cancelled
Continuous integration / library (windows-latest, stable) (push) Has been cancelled
Continuous integration / miri (push) Has been cancelled
Continuous integration / lints (push) Has been cancelled
Continuous integration / no-std (push) Has been cancelled
Continuous integration / features (push) Has been cancelled
Continuous integration / minimal-versions (push) Has been cancelled
Merge pull request #119 from shepmaster/comparison-exceeds-msrv
Comparison tests may exceed the MSRV
2026-02-19 09:30:22 -05:00
.github Only run the property tests on stable Rust and up 2026-02-19 09:18:50 -05:00
asmasm Overwrite original version with refresh 2024-10-09 13:18:03 -04:00
comparison Upgrade proptest 2026-02-19 09:18:50 -05:00
src Document why xxhash3_128::Hasher doesn't implement the Hasher trait 2025-09-03 12:01:46 -04:00
twox-hash-sum Overwrite original version with refresh 2024-10-09 13:18:03 -04:00
xx_hash-sys Calm Clippy warning in testing code 2026-02-19 08:44:08 -05:00
.gitignore Overwrite original version with refresh 2024-10-09 13:18:03 -04:00
.gitmodules Overwrite original version with refresh 2024-10-09 13:18:03 -04:00
Cargo.toml Release version 2.1.2 2025-09-03 13:13:15 -04:00
CHANGELOG.md Update the changelog 2025-09-03 13:12:54 -04:00
clippy.toml Overwrite original version with refresh 2024-10-09 13:18:03 -04:00
LICENSE.txt Add crate metadata 2015-05-08 23:03:18 -04:00
README.md Mention XxHash3_128 in the top-level docs 2025-09-03 12:01:46 -04:00

A Rust implementation of the xxHash algorithm.

Crates.io Documentation Build Status

Examples

These examples use XxHash64 but the same ideas can be used for XxHash32, XxHash3_64, or XxHash3_128.

Hashing arbitrary data

When all the data is available at once

use twox_hash::XxHash64;

let seed = 1234;
let hash = XxHash64::oneshot(seed, b"some bytes");
assert_eq!(0xeab5_5659_a496_d78b, hash);

When the data is streaming

use std::hash::Hasher as _;
use twox_hash::XxHash64;

let seed = 1234;
let mut hasher = XxHash64::with_seed(seed);
hasher.write(b"some");
hasher.write(b" ");
hasher.write(b"bytes");
let hash = hasher.finish();
assert_eq!(0xeab5_5659_a496_d78b, hash);

In a HashMap

With a default seed

use std::{collections::HashMap, hash::BuildHasherDefault};
use twox_hash::XxHash64;

let mut hash = HashMap::<_, _, BuildHasherDefault<XxHash64>>::default();
hash.insert(42, "the answer");
assert_eq!(hash.get(&42), Some(&"the answer"));

With a random seed

use std::collections::HashMap;
use twox_hash::xxhash64;

let mut hash = HashMap::<_, _, xxhash64::RandomState>::default();
hash.insert(42, "the answer");
assert_eq!(hash.get(&42), Some(&"the answer"));

With a fixed seed

use std::collections::HashMap;
use twox_hash::xxhash64;

let mut hash = HashMap::with_hasher(xxhash64::State::with_seed(0xdead_cafe));
hash.insert(42, "the answer");
assert_eq!(hash.get(&42), Some(&"the answer"));

Feature Flags

name description
xxhash32 Include the XxHash32 algorithm
xxhash64 Include the XxHash64 algorithm
xxhash3_64 Include the XxHash3_64 algorithm
xxhash3_128 Include the XxHash3_128 algorithm
random Create random instances of the hashers
serialize Serialize and deserialize hasher state with Serde
std Use the Rust standard library. Enable this if you want SIMD support in XxHash3_64 or XxHash3_128
alloc Use the Rust allocator library. Enable this if you want to create XxHash3_64 or XxHash3_128 with dynamic secrets

Benchmarks

See benchmarks in the comparison README.

Contributing

  1. Fork it (https://github.com/shepmaster/twox-hash/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Add a failing test.
  4. Add code to pass the test.
  5. Commit your changes (git commit -am 'Add some feature')
  6. Ensure tests pass.
  7. Push to the branch (git push origin my-new-feature)
  8. Create a new Pull Request