mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
inline hash function to save extra alloc (#53)
This commit is contained in:
parent
fd179b4a86
commit
1f10b4026d
@ -2,7 +2,6 @@ package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -10,10 +9,18 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
offset64 = 14695981039346656037
|
||||
prime64 = 1099511628211
|
||||
)
|
||||
|
||||
func Hash(key []byte) uint64 {
|
||||
h := fnv.New64a()
|
||||
h.Write(key)
|
||||
return h.Sum64()
|
||||
var s uint64 = offset64
|
||||
for _, c := range key {
|
||||
s ^= uint64(c)
|
||||
s *= prime64
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func Exists(path string) bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user