Skip to main content

Module hash

Module hash 

Source
Expand description

SIMD-optimized hash functions for key-value store operations.

This module provides fast hash functions optimized for short string keys, with automatic SIMD dispatch (AVX-512 → AVX2 → SSE2 → Scalar).

§Example

use trueno::hash::{hash_key, hash_keys_batch};

// Single key hash
let h = hash_key("hello");
assert_ne!(h, 0);

// Batch hash (SIMD-optimized)
let keys = ["a", "b", "c", "d"];
let hashes = hash_keys_batch(&keys);
assert_eq!(hashes.len(), 4);

§Performance

  • Single key: ~2-5ns (FxHash-equivalent)
  • Batch (8 keys): ~10-15ns with AVX2 (vs ~20-40ns sequential)
  • Batch (16 keys): ~15-20ns with AVX-512

Functions§

hash_bytes
Hash raw bytes to u64.
hash_key
Hash a single key to u64.
hash_keys_batch
Hash multiple keys in batch (SIMD-optimized).
hash_keys_batch_with_backend
Hash multiple keys with explicit backend selection.