What is the purpose of path hints?
sandeeprapido opened this issue · comments
sandeeprapido commented
I am trying to understand how exactly I can use path hint methods. Could you please give some examples in the Readme. That would be helpful.
Josh Baker commented
Ok. I'll try to put together some documentation on the README.
Josh Baker commented
I added a PATH_HINT markdown file.
Dev Ojha commented
The benchmark code helped me understand the API, it wasn't clear to me prior to reading that that the functions using path hints mutated the hint
tommie commented
I wonder if this API would be helpful:
type PathContext struct {
bt *BTree
hint PathHint
}
func (c *PathContext) Delete(key interface{}) interface{} {
return c.bt.DeleteHint(key, &c.hint)
}
func (c *PathContext) Get(key interface{}) interface{} {
return c.bt.GetHint(key, &c.hint)
}
func (c *PathContext) Set(key interface{}) interface{} {
return c.bt.SetHint(key, &c.hint)
}
func main() {
bt := New(func(a, b interface{}) bool {
return a.(string) < b.(string)
})
c := bt.PathContext()
c.Set("abc")
fmt.Println(c.Get("abc"))
c.Delete("abc")
}
Josh Baker commented
@tommie Your PathContext idea is slick. I'm not sure that it's best suited for adding directly to this library but I can see how it others might find it convenient.