Giter Site home page Giter Site logo

What is the purpose of path hints? about btree HOT 5 OPEN

tidwall avatar tidwall commented on May 24, 2024
What is the purpose of path hints?

from btree.

Comments (5)

tidwall avatar tidwall commented on May 24, 2024 6

I added a PATH_HINT markdown file.

from btree.

tommie avatar tommie commented on May 24, 2024 2

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

from btree.

tidwall avatar tidwall commented on May 24, 2024

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

from btree.

ValarDragon avatar ValarDragon commented on May 24, 2024

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

from btree.

tidwall avatar tidwall commented on May 24, 2024

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

from btree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.