Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the purpose of path hints? #7

Open
sandeeprapido opened this issue Jun 12, 2021 · 5 comments
Open

What is the purpose of path hints? #7

sandeeprapido opened this issue Jun 12, 2021 · 5 comments

Comments

@sandeeprapido
Copy link

sandeeprapido commented Jun 12, 2021

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.

@tidwall
Copy link
Owner

tidwall commented Jul 21, 2021

Ok. I'll try to put together some documentation on the README.

@tidwall
Copy link
Owner

tidwall commented Jul 30, 2021

I added a PATH_HINT markdown file.

@ValarDragon
Copy link
Contributor

ValarDragon commented Sep 14, 2021

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
Copy link

tommie commented Sep 30, 2021

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")
}

https://play.golang.org/p/wWcBVE-YwfY

@tidwall
Copy link
Owner

tidwall commented Oct 6, 2021

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants