2018-11-09 17:25:50 +00:00
|
|
|
package index
|
2017-11-30 15:08:12 +00:00
|
|
|
|
|
|
|
import (
|
2018-11-09 17:25:50 +00:00
|
|
|
"log"
|
|
|
|
|
2017-11-30 15:08:12 +00:00
|
|
|
"github.com/OneOfOne/xxhash"
|
|
|
|
"github.com/sp4ke/hashmap"
|
|
|
|
)
|
|
|
|
|
2018-11-09 17:25:50 +00:00
|
|
|
type Index = *hashmap.RBTree
|
|
|
|
type HashTree = *hashmap.RBTree
|
|
|
|
|
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)
|
|
|
|
}
|