22// Use of this source code is governed by a BSD-style
33// license that can be found in the LICENSE file.
44
5- // Package murmer3 provides functions implementing the Murmur3 hashing algorithm.
5+ // Package murmur3 provides functions implementing the Murmur3 hashing algorithm.
66// The ClojureJVM version imported the Guava Murmur3 implementation
77// and made some changes.
88// For ClojureCLR and here, I copied the API stubs, then implemented the API
@@ -22,14 +22,17 @@ const n uint32 = 0xe6546b64
2222
2323// The public interface
2424
25+ // HashInt32 computes a hash value for an int32
2526func HashInt32 (input int32 ) uint32 {
2627 return HashUInt32 (uint32 (input ))
2728}
2829
30+ // HashInt64 computes a hash value for an int64
2931func HashInt64 (input int64 ) uint32 {
3032 return HashUInt64 (uint64 (input ))
3133}
3234
35+ // HashUInt32 computes a hash value for a uint32
3336func HashUInt32 (input uint32 ) uint32 {
3437 if input == 0 {
3538 return 0
@@ -40,6 +43,7 @@ func HashUInt32(input uint32) uint32 {
4043 return Finalize (hash , 4 )
4144}
4245
46+ // HashUInt64 computes a hash value for a uint64
4347func HashUInt64 (input uint64 ) uint32 {
4448 if input == 0 {
4549 return 0
@@ -57,6 +61,7 @@ func HashUInt64(input uint64) uint32 {
5761 return Finalize (hash , 8 )
5862}
5963
64+ // HashString computes a hash value for a string
6065func HashString (input string ) uint32 {
6166
6267 hash := seed
@@ -88,13 +93,15 @@ func HashString(input string) uint32 {
8893 return Finalize (hash , int32 (len ))
8994}
9095
96+ // MixKey scrambles the bits in 32-bit value
9197func MixKey (key uint32 ) uint32 {
9298 key *= c1
9399 key = rotateLeft (key , r1 )
94100 key *= c2
95101 return key
96102}
97103
104+ // MixHash mixes a new 32-bit value into a given hash value
98105func MixHash (hash uint32 , key uint32 ) uint32 {
99106 hash ^= key
100107 hash = rotateLeft (hash , r2 )
@@ -103,7 +110,7 @@ func MixHash(hash uint32, key uint32) uint32 {
103110
104111}
105112
106- // finalize forces all bits of a hash block to avalanche
113+ // Finalize forces all bits of a hash block to avalanche
107114func Finalize (hash uint32 , length int32 ) uint32 {
108115 hash ^= uint32 (length )
109116 hash ^= hash >> 16
@@ -114,6 +121,7 @@ func Finalize(hash uint32, length int32) uint32 {
114121 return hash
115122}
116123
124+ // FinalizeCollHash forces all bits of a hash block to avalanche, and add in a length count
117125func FinalizeCollHash (hash uint32 , count int32 ) uint32 {
118126 h1 := seed
119127 k1 := MixKey (hash )
0 commit comments