diff options
author | Felix Lange <fjl@twurst.com> | 2016-07-20 00:45:42 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-07-20 00:45:42 +0800 |
commit | 4d014d6d7e30f470725e3a0984f706292fe76366 (patch) | |
tree | fc120dad7d7313a3e2e387537a6d48a67f01ffbb /Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/util/hash.go | |
parent | a4c4125b1155d9276614029163b498a17643f0f2 (diff) | |
download | go-tangerine-4d014d6d7e30f470725e3a0984f706292fe76366.tar.gz go-tangerine-4d014d6d7e30f470725e3a0984f706292fe76366.tar.zst go-tangerine-4d014d6d7e30f470725e3a0984f706292fe76366.zip |
Godeps: bump github.com/syndtr/goleveldb/... to ab8b5dcf104
Diffstat (limited to 'Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/util/hash.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/util/hash.go | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/util/hash.go b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/util/hash.go index 54903660f..7f3fa4e2c 100644 --- a/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/util/hash.go +++ b/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/util/hash.go @@ -7,38 +7,38 @@ package util import ( - "bytes" "encoding/binary" ) // Hash return hash of the given data. func Hash(data []byte, seed uint32) uint32 { // Similar to murmur hash - var m uint32 = 0xc6a4a793 - var r uint32 = 24 - h := seed ^ (uint32(len(data)) * m) + const ( + m = uint32(0xc6a4a793) + r = uint32(24) + ) + var ( + h = seed ^ (uint32(len(data)) * m) + i int + ) - buf := bytes.NewBuffer(data) - for buf.Len() >= 4 { - var w uint32 - binary.Read(buf, binary.LittleEndian, &w) - h += w + for n := len(data) - len(data)%4; i < n; i += 4 { + h += binary.LittleEndian.Uint32(data[i:]) h *= m h ^= (h >> 16) } - rest := buf.Bytes() - switch len(rest) { + switch len(data) - i { default: panic("not reached") case 3: - h += uint32(rest[2]) << 16 + h += uint32(data[i+2]) << 16 fallthrough case 2: - h += uint32(rest[1]) << 8 + h += uint32(data[i+1]) << 8 fallthrough case 1: - h += uint32(rest[0]) + h += uint32(data[i]) h *= m h ^= (h >> r) case 0: |