Skip to content

Add Int32Murmur3Hasher and Int64WangHasher - #46

Merged
marius-bughiu merged 2 commits into
mainfrom
feature/int32-murmur3-int64-wang-hashers
Apr 18, 2026
Merged

Add Int32Murmur3Hasher and Int64WangHasher#46
marius-bughiu merged 2 commits into
mainfrom
feature/int32-murmur3-int64-wang-hashers

Conversation

@marius-bughiu

Copy link
Copy Markdown
Owner

Summary

Adds the two remaining planned hashers from milestone 1.1.0, completing issue #12:

  • Int32Murmur3Hasher — Murmur3 fmix32 finalizer for int keys. Complements the existing Int64Murmur3Hasher; prefer over Int32WangNaiveHasher when key distribution is clustered or adversarial. Both multiply constants (0x85ebca6b, 0xc2b2ae35) match the MurmurHash3 reference implementation. Maps 0 → 0 (fixed point of fmix32).

  • Int64WangHasher — Thomas Wang 64-bit integer hash for long keys. Complements the existing Int32WangNaiveHasher; faster than Int64Murmur3Hasher while providing better avalanche than a plain XOR-fold. Invertible on ulong, so truncation to 32 bits is the only source of collisions. Does not map 0 → 0 (documented in XML remarks).

Both types are zero-allocation structs with AggressiveInlining and full XML documentation, consistent with every other hasher in the library.

Files changed

  • src/Celerity/Hashing/Int32Murmur3Hasher.cs — new hasher
  • src/Celerity/Hashing/Int64WangHasher.cs — new hasher
  • src/Celerity.Tests/Hashing/Int32Murmur3HasherTests.cs — new tests
  • src/Celerity.Tests/Hashing/Int64WangHasherTests.cs — new tests
  • CHANGELOG.md[Unreleased] entries for both hashers and their test suites
  • ISSUES.mdAdd comprehensive roadmap and automated issue generation #12 marked fixed in 1.1.0 (all five hashers now complete)
  • ROADMAP.md — hasher item (Add more hash function implementations #24) marked done

Test plan

  • dotnet build succeeds with 0 errors
  • dotnet test passes all 315 tests (verified locally with DOTNET_ROLL_FORWARD=Major)
  • Int32Murmur3HasherTests — exact anchor values, determinism, avalanche, distinctness sweep, CelerityDictionary/CeleritySet integration including default(int) out-of-band slot
  • Int64WangHasherTests — exact anchor values, determinism, avalanche, distinctness sweep, CelerityDictionary/CeleritySet integration including default(long) out-of-band slot
  • CI green on push

marius-bughiu and others added 2 commits April 16, 2026 10:16
GuidHasher reinterprets the 128-bit Guid as two ulongs via Unsafe.As,
runs Murmur3 fmix64 on each half, and XORs the mixed halves before
truncating to 32 bits. This gives every input bit the chance to reach
the final hash even when inputs share a long prefix (database-generated
sequences) or the fixed V4 version/variant nibbles.

Prefer GuidHasher over DefaultHasher<Guid> on hot paths: it is a struct
with AggressiveInlining, so the JIT fully inlines it and avoids the
EqualityComparer<T>.Default virtual dispatch.

Tests cover the Guid.Empty -> 0 anchor, determinism across calls and
struct instances, avalanche on both halves, shared-prefix and
shared-suffix divergence, two 1000-value distinctness sweeps
(sequential and random), and integration with CeleritySet /
CelerityDictionary (including the default(Guid) out-of-band slot).

Advances ROADMAP 1.1.0 hashers (GuidHasher now done) and updates
ISSUES #12.
…0 hashers

Adds the two remaining planned hashers from milestone 1.1.0 (#12):

- Int32Murmur3Hasher: Murmur3 fmix32 finalizer for int keys. Excellent
  avalanche properties; prefer over Int32WangNaiveHasher on clustered or
  adversarial key distributions. Maps 0 → 0 (fixed point of fmix32).

- Int64WangHasher: Thomas Wang 64-bit integer hash for long keys. Faster
  than Int64Murmur3Hasher while providing better avalanche than a plain
  XOR-fold. Invertible on ulong, so truncation to 32 bits is the only
  source of collisions.

Each hasher is a zero-allocation struct with AggressiveInlining and full
XML documentation. Tests cover exact anchor values, determinism across
calls and struct instances, high-bit avalanche, 1000-value distinctness
sweeps, and integration with CelerityDictionary and CeleritySet (including
the default-key out-of-band slot). All 315 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@marius-bughiu
marius-bughiu merged commit 978beb3 into main Apr 18, 2026
1 check passed
@marius-bughiu
marius-bughiu deleted the feature/int32-murmur3-int64-wang-hashers branch July 24, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant