xxh3
Ruby bindings for XXH3 — the modern, SIMD-friendly hash family from
Yann Collet. Exposes both the 64-bit (XXH3_64bits) and the 128-bit
(XXH3_128bits) variants through a Digest::Class-compatible API.
Backed by the pure-Rust xxhash-rust
crate, so there's no system-library runtime dependency.
No existing Ruby gem exposes XXH3-128; the handful of classic XXH gems
(xxhash, xxhash-ruby) only cover the legacy XXH32/XXH64 algorithms.
Installation
gem install xxh3
Usage
require "xxh3"
# One-shot — fastest path (no wrapper object).
XXH3.xxh3_digest("hello") # => "\xB9\x06…" (8-byte binary)
XXH3.xxh128_digest("hello") # => 16-byte binary
# Digest::Class-compatible wrapper (64-bit and 128-bit).
XXH3::Digest64.hexdigest("hello") # => "b906..." (16 hex chars)
XXH3::Digest128.hexdigest("hello") # => "…" (32 hex chars)
# Streaming.
h = XXH3::Digest128.new
h.update("hello, ")
h << "xxh3"
h.hexdigest # => 32-hex digest, state then reset
Digest:: namespace aliases
Mirror the Digest::Blake3 convention from Shopify/blake3-rb:
require "digest/xxh3"
Digest::XXH3.hexdigest("abc") # 64-bit
Digest::XXH128.hexdigest("abc") # 128-bit
Digest::XXH3 is an alias for XXH3::Digest64; Digest::XXH128 is an alias
for XXH3::Digest128. Both inherit from Digest::Class and expose the
standard #update/#<</#reset/#digest/#hexdigest/#finish API.
Performance
XXH3 runs at roughly one byte per cycle on modern x86 (~5 GB/s single-core). For short inputs it is typically faster than a memcpy of the same bytes, which is the whole reason it has replaced XXH64 as the default in zstd, LZ4, and most modern content-defined-chunking codecs.
XXH3 vs XXH64
XXH3 is a distinct algorithm from XXH64 — not a newer version of it. Outputs differ; nothing is wire-compatible with legacy XXH64 gems. If you need compatibility with XXH64 outputs produced by another system, use an XXH64 gem instead; this gem intentionally targets the modern XXH3 family.
Development
bundle install
bundle exec rake compile
bundle exec rake test
License
MIT.