Debian Codegraph @

external/murmur3/murmur64.go

raw
1 package murmur3
2
3 import (
4 "hash"
5 )
6
7 // Make sure interfaces are correctly implemented.
8 var (
9 _ hash.Hash = new(digest64)
10 _ hash.Hash64 = new(digest64)
11 _ bmixer = new(digest64)
12 )
13
14 // digest64 is half a digest128.
15 type digest64 digest128
16
17 func New64() hash.Hash64 {
18 d := (*digest64)(New128().(*digest128))
19 return d
20 }
21
22 func (d *digest64) Sum(b []byte) []byte {
23 h1 := d.h1
24 return append(b,
25 byte(h1>>56), byte(h1>>48), byte(h1>>40), byte(h1>>32),
26 byte(h1>>24), byte(h1>>16), byte(h1>>8), byte(h1))
27 }
28
29 func (d *digest64) Sum64() uint64 {
30 h1, _ := (*digest128)(d).Sum128()
31 return h1
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 {
40 d := &digest128{h1: 0, h2: 0}
41 d.tail = d.bmix(data)
42 d.clen = len(data)
43 h1, _ := d.Sum128()
44 return h1
45 }