core: (fixes #1286) clean up and extend Murmur3 hash implementation
This MR addresses three of the four sub-issues raised in the issue #1286.
Point 1: Add Hash::Function::Murmur3_x64 as an opt-in x64 class - Exposes the x64 algorithm through a new class ns3::Hash::Function::Murmur3_x64 that follows the same interface as the existing Murmur3 and Fnv1a implementations. Usage:
Hasher h(Create<Hash::Function::Murmur3_x64>());
uint64_t v = h.GetHash64(buffer, size);It produces different hash values for the same input, so it is an explicit opt-in. The default ns3::Hasher The constructor is unchanged, and no existing simulation results are affected.
limitation: MurmurHash3_x64_128_incr takes a uint32_t seed rather than a running state, so each GetHash64 call re-seeds from SEED independently. Successive calls without clear() do not accumulate input, documented in the class Doxygen. Murmur3_x64 is excluded from IncrementalTestCase .
Point 3: Refactor dead MurmurHash3_x64_128 into static helpers - MurmurHash3_x64_128 was a monolithic all in one function inside Murmur3Implementation which was never called from the Murmur3 wrapper (dead code).
Rather than deleting it, it is split into two static helpers following the _incr and _fin pattern already used for the x86_32 and x86_128 variants:
MurmurHash3_x64_128_incr- seedsh1 = h2 = seed, processes all blocks and the tail, writes the pre-finalization state as twouint64_twords.MurmurHash3_x64_128_fin- applies the length XOR and fmix avalanche, writes the lower 32 bits of each finalized word as twouint32_tvalues.
Point 4: Remove unnecessary static_cast in Murmur3::GetHash64 - MurmurHash3_x86_128_incr and MurmurHash3_x86_128_fin both take std::size_t parameters. The call site previously cast size and m_size64 to int before passing them, which is unnecessary and may lead to truncation for large inputs. These casts are removed so that the full std::size_t value is preserved. The existing (uint32_t*)(void*) aliasing workaround is left unchanged.
Tests
Murmur3_x64TestCase added to hash-test-suite.cc with three checks:
- Absolute 64-bit reference value compared against the standard test key (
"The quick brown fox jumped over the lazy dogs.", seed0x8BADF00D):0xdd33a0aae80bc4c8. GetHash32equals the lower 32 bits ofGetHash64, verifies the 32/64 consistency check.Murmur3_x64output differs fromMurmur3(x86) output on the same input, guards against the two algorithms accidentally sharing a code path.