github.com/m3db/stackmurmur3@v1.0.1/murmur64.go (about)

     1  package murmur3
     2  
     3  // Digest64 is half a digest128.
     4  type Digest64 Digest128
     5  
     6  // New64 returns a 64-bit hasher
     7  func New64() Digest64 { return New64WithSeed(0) }
     8  
     9  // New64WithSeed returns a 64-bit hasher set with explicit seed value
    10  func New64WithSeed(seed uint32) Digest64 {
    11  	return Digest64(New128WithSeed(seed))
    12  }
    13  
    14  func (d Digest64) Size() int {
    15  	return 8
    16  }
    17  
    18  func (d Digest64) Sum(b []byte) []byte {
    19  	h1 := d.Sum64()
    20  	return append(b,
    21  		byte(h1>>56), byte(h1>>48), byte(h1>>40), byte(h1>>32),
    22  		byte(h1>>24), byte(h1>>16), byte(h1>>8), byte(h1))
    23  }
    24  
    25  func (d Digest64) Sum64() uint64 {
    26  	h1, _ := Digest128(d).Sum128()
    27  	return h1
    28  }
    29  
    30  func (d Digest64) Write(p []byte) Digest64 {
    31  	return Digest64(Digest128(d).Write(p))
    32  }
    33  
    34  // Sum64 returns the MurmurHash3 sum of data. It is equivalent to the
    35  // following sequence (without the extra burden and the extra allocation):
    36  //     hasher := New64()
    37  //     hasher.Write(data)
    38  //     return hasher.Sum64()
    39  func Sum64(data []byte) uint64 { return Sum64WithSeed(data, 0) }
    40  
    41  // Sum64WithSeed returns the MurmurHash3 sum of data. It is equivalent to the
    42  // following sequence (without the extra burden and the extra allocation):
    43  //     hasher := New64WithSeed(seed)
    44  //     hasher.Write(data)
    45  //     return hasher.Sum64()
    46  func Sum64WithSeed(data []byte, seed uint32) uint64 {
    47  	return New64WithSeed(seed).Write(data).Sum64()
    48  }