Murmur3 32-bit hashing helpers over raw byte storage.
murmur32Scramble
(value -- value) Applies the Murmur3 32-bit block scramble.- Takes and returns
Nat32. Both multiplications and the rotation use wrapping 32-bit arithmetic; the result is a new value.
murmur3_32
(key size seed -- hash) Hashes raw bytes with Murmur3 x86 32-bit finalization.keyis aNatxaddress,seedisNat32, andsizeis a nonnegative integer byte count representable asNat32. Larger counts are not checked and are truncated to their low 32 bits.- For nonzero
size, provide readable storage covering the whole input. Full-word reads requirekeyto be 4-byte aligned; arbitrary-unaligned byte storage is not supported. The helper performs no run-time bounds or null validation. - Full blocks use native
Nat32word order. On little-endian targets this is MurmurHash3 x86-32. Tail bytes are assembled little-endian at bit positions 0, 8, and 16. - A zero count performs no input read, so address zero is usable for an empty input;
keyis not dereferenced. The buffer is not modified and the returnedNat32does not borrow it.
The helper is one-shot; there is no incremental interface (compare sha1).
Input model
Pass a Natx address and a byte count; the module has no Text or StringView overload.
- Adapt Text with
storageAddressandtextSize:text storageAddress text textSize seed murmur3_32. - Adapt StringView with its
dataandsize:view.data storageAddress view.size seed murmur3_32. - These adaptations have the same readable-extent and full-word alignment obligations as a direct call.
Examples
Scramble step
"control" use
"murmurHash" use
{} () {} [
0n32 murmur32Scramble printStack _:;
1n32 murmur32Scramble printStack _:;
] "main" exportFunction
Expected Output During Compilation
0n32
3277036125n32
Zero-size input
"control" use
"murmurHash" use
{} () {} [
0nx 0 0n32 murmur3_32 printStack _:;
0nx 0 1n32 murmur3_32 printStack _:;
] "main" exportFunction
Expected Output During Compilation
0n32
1364076727n32
Whole input and seed effect
"String" use
"control" use
"murmurHash" use
{} Int32 {} [
(97n8 98n8 99n8) storageAddress 3 0n32 murmur3_32 toString print
"\n" print
(97n8 98n8 99n8) storageAddress 3 1n32 murmur3_32 toString print
0
] "main" exportFunction
Expected Output
3017643002
2859854335
See also
- sha1: Whole-input and incremental SHA-1 hashing helpers.