gosuki/index.go

27 lines
684 B
Go
Raw Normal View History

2017-11-30 15:08:12 +00:00
package main
import (
"github.com/OneOfOne/xxhash"
"github.com/sp4ke/hashmap"
)
2018-11-05 01:40:11 +00:00
// In memory index used for fast lookup of url->node pairs
2017-11-30 15:08:12 +00:00
// to quickly detect bookmark which changed when bookmarks are reloaded
// from browser on a watch event
// Input `in` must be of type []byte
// The index is a map of [urlhash]*Node
func xxHashFunc(in interface{}) uint64 {
input, ok := in.(string)
if !ok {
log.Panicf("wrong data type to hash, exptected string given %T", in)
}
sum := xxhash.ChecksumString64(input)
//log.Debugf("Calculating hash of %s as %d", input, sum)
return sum
}
// Returns *hashmap.RBTree
func NewIndex() *hashmap.RBTree {
return hashmap.New(xxHashFunc)
}