View source code
							
							
						
								Display the source code in std/digest/murmurhash.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								Improve this page
							
							
					
								Quickly fork, edit online, and submit a pull request for this page.
								Requires a signed-in GitHub account. This works well for small changes.
								If you'd like to make larger changes you may want to consider using
								local clone.
							
						Module std.digest.murmurhash
Computes MurmurHash hashes of arbitrary data. MurmurHash is a non-cryptographic hash function suitable for general hash-based lookup. It is optimized for x86 but can be used on all architectures.
The current version is MurmurHash3, which yields a 32-bit or 128-bit hash value. The older MurmurHash 1 and 2 are currently not supported.
MurmurHash3 comes in three flavors, listed in increasing order of throughput:
- MurmurHash3!32produces a 32-bit value and is optimized for 32-bit architectures
- MurmurHash3!(128, 32)produces a 128-bit value and is optimized for 32-bit architectures
- MurmurHash3!(128, 64)produces a 128-bit value and is optimized for 64-bit architectures
Note
- MurmurHash3!(128, 32)and- MurmurHash3!(128, 64)produce different values.
- The current implementation is optimized for little endian architectures. It will exhibit different results on big endian architectures and a slightly less uniform distribution.
This module conforms to the APIs defined in std.
This module publicly imports std and can be used as a stand-alone module.
References
Example
// MurmurHash3!32, MurmurHash3!(128, 32) and MurmurHash3!(128, 64) implement
// the std.digest Template API.
static assert(isDigest!(MurmurHash3!32));
// The convenient digest template allows for quick hashing of any data.
ubyte[4] hashed = digest!(MurmurHash3!32)([1, 2, 3, 4]);
writeln(hashed); // [0, 173, 69, 68]
Example
// One can also hash ubyte data piecewise by instanciating a hasher and call
// the 'put' method.
const(ubyte)[] data1 = [1, 2, 3];
const(ubyte)[] data2 = [4, 5, 6, 7];
// The incoming data will be buffered and hashed element by element.
MurmurHash3!32 hasher;
hasherExample
// Using `putElements`, `putRemainder` and `finalize` you gain full
// control over which part of the algorithm to run.
// This allows for maximum throughput but needs extra care.
// Data type must be the same as the hasher's element type:
// - uint for MurmurHash3!32
// - uint[4] for MurmurHash3!(128, 32)
// - ulong[2] for MurmurHash3!(128, 64)
const(uint)[] data = [1, 2, 3, 4];
// Note the hasher starts with 'Fast'.
MurmurHash3!32 hasher;
// Push as many array of elements as you need. The less calls the better.
hasherStructs
| Name | Description | 
|---|---|
| 
									MurmurHash3
								 | Implements the MurmurHash3 functions. You can specify the sizeof the
 hash in bit. For 128 bit hashes you can specify whether to optimize for 32
 or 64 bit architectures. If you don't specify theoptvalue it will select
 the fastest version of the host platform. | 
Authors
Guillaume Chatelet
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.