在 Go 中快速、完整的 murmur3。
Native Go implementation of Austin Appleby's third MurmurHash revision (aka MurmurHash3).
Includes 32, 64, and 128 bit sums, seeding functions, string functions that hash without converting to a slice, and streaming hashes implementing Go's standard Hash and Cloner interfaces.
This library started as a fork of spaolacci/murmur3. The reference algorithm has been slightly hacked as to support the streaming mode required by Go's standard Hash interface.
Unlike the canonical source, this library always reads bytes as little endian numbers. This makes the hashes portable across architectures, although does mean that hashing is a bit slower on big endian architectures.
This library uses no unsafe. Bytes are read with plain indexing, which the
compiler turns into single word sized loads on architectures that allow
unaligned access, and the loops are shaped so that the compiler proves every
index in bounds. Strings are hashed through one implementation generic over
string | []byte, so hashing a string does not copy it and does not
allocate.
Earlier versions shipped hand rolled amd64 assembly for the 64 and 128 bit sums. That assembly was removed once the compiler's output caught up: as of Go 1.27, the pure Go code is faster than the old assembly for every input under 64 bytes, for keys of varying length, and for every 32 bit sum, and 1 to 7 percent slower on fixed inputs of 64 bytes and more. The 32 bit assembly was removed for the same reason back in Go 1.11. See the benchmarks below.
Testing includes comparing random inputs against the canonical implementation, and testing length 0 through 100 inputs to force the block loop, the trailing block, and all tail lengths.
Because this code always reads input as little endian, testing against the canonical source is skipped for big endian architectures. The canonical source just converts bytes to numbers, meaning on big endian architectures, it will use different numbers for its hashing.
Cycles per call from perf (cycles:u at a fixed iteration count, minimum of
three runs) on a Comet Lake i7-10710U, so CPU frequency and thermal
throttling drop out. asm is the amd64 assembly this library shipped through
v1.1.8; the other columns are this code built by that Go release. Go 1.26
is the minimum this module declares. Sizes
rows exercise the block loop, Branches rows the 0 to 16 byte tail, and
RandomLengths rows draw an xorshift length in [0, 64) on every call.
…暂无开放 Issues,或尚未同步最近议题。