This package provides an in-memory quadtree implementation for Go.
To start using QTree, install Go and run go get
:
$ go get -u github.com/tidwall/qtree
// create a QTree
var tr qtree.QTree
// insert a point
tr.Insert([2]float64{-112.0078, 33.4373}, [2]float64{-112.0078, 33.4373}, "PHX")
// insert a box
tr.Insert([2]float64{10, 10}, [2]float64{20, 20}, "rect")
// search
tr.Search([2]float64{-112.1, 33.4}, [2]float64{-112.0, 33.5},
func(min, max [2]float64, value interface{}) bool {
println(value.(string)) // prints "PHX"
},
)
// delete
tr.Delete([2]float64{-112.0078, 33.4373}, [2]float64{-112.0078, 33.4373}, "PHX")
Pretty, pretty, pretty good.
qtree
source code is available under the MIT License.