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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
@ -10,10 +9,18 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
offset64 = 14695981039346656037
|
||||||
|
prime64 = 1099511628211
|
||||||
|
)
|
||||||
|
|
||||||
func Hash(key []byte) uint64 {
|
func Hash(key []byte) uint64 {
|
||||||
h := fnv.New64a()
|
var s uint64 = offset64
|
||||||
h.Write(key)
|
for _, c := range key {
|
||||||
return h.Sum64()
|
s ^= uint64(c)
|
||||||
|
s *= prime64
|
||||||
|
}
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func Exists(path string) bool {
|
func Exists(path string) bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user