Add Int32Murmur3Hasher and Int64WangHasher - #46
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the two remaining planned hashers from milestone 1.1.0, completing issue #12:
Int32Murmur3Hasher— Murmur3 fmix32 finalizer forintkeys. Complements the existingInt64Murmur3Hasher; prefer overInt32WangNaiveHasherwhen key distribution is clustered or adversarial. Both multiply constants (0x85ebca6b,0xc2b2ae35) match the MurmurHash3 reference implementation. Maps0 → 0(fixed point of fmix32).Int64WangHasher— Thomas Wang 64-bit integer hash forlongkeys. Complements the existingInt32WangNaiveHasher; faster thanInt64Murmur3Hasherwhile providing better avalanche than a plain XOR-fold. Invertible onulong, so truncation to 32 bits is the only source of collisions. Does not map0 → 0(documented in XML remarks).Both types are zero-allocation structs with
AggressiveInliningand full XML documentation, consistent with every other hasher in the library.Files changed
src/Celerity/Hashing/Int32Murmur3Hasher.cs— new hashersrc/Celerity/Hashing/Int64WangHasher.cs— new hashersrc/Celerity.Tests/Hashing/Int32Murmur3HasherTests.cs— new testssrc/Celerity.Tests/Hashing/Int64WangHasherTests.cs— new testsCHANGELOG.md—[Unreleased]entries for both hashers and their test suitesISSUES.md— Add comprehensive roadmap and automated issue generation #12 markedfixed in 1.1.0(all five hashers now complete)ROADMAP.md— hasher item (Add more hash function implementations #24) markeddoneTest plan
dotnet buildsucceeds with 0 errorsdotnet testpasses all 315 tests (verified locally withDOTNET_ROLL_FORWARD=Major)Int32Murmur3HasherTests— exact anchor values, determinism, avalanche, distinctness sweep,CelerityDictionary/CeleritySetintegration includingdefault(int)out-of-band slotInt64WangHasherTests— exact anchor values, determinism, avalanche, distinctness sweep,CelerityDictionary/CeleritySetintegration includingdefault(long)out-of-band slot