This commit is contained in:
re 2022-12-12 15:28:16 +03:00
parent fc55586978
commit b969e73439
5 changed files with 18 additions and 12 deletions

View File

@ -1,9 +1,9 @@
**This project has been archived, please use [tidwall/rtree](https://github.com/tidwall/rtree) instead.**
**This project has been archived, please use [tidwall/rtree](https://git.internal/re/rtree) instead.**
RTree implementation for Go
===========================
[![GoDoc](https://godoc.org/github.com/tidwall/rtred?status.svg)](https://godoc.org/github.com/tidwall/rtred)
[![GoDoc](https://godoc.org/git.internal/re/rtred?status.svg)](https://godoc.org/git.internal/re/rtred)
This package provides an in-memory R-Tree implementation for Go, useful as a spatial data structure.
It has support for 1-20 dimensions, and can store and search multidimensions interchangably in the same tree.

View File

@ -1,7 +1,7 @@
package base
import (
"github.com/tidwall/tinyqueue"
"git.internal/re/tinyqueue"
)
type queueItem struct {

4
go.mod
View File

@ -1,5 +1,5 @@
module github.com/tidwall/rtred
module git.internal/re/rtred
go 1.15
require github.com/tidwall/tinyqueue v0.1.1
require git.internal/re/tinyqueue v0.1.3

4
go.sum
View File

@ -1,2 +1,2 @@
github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=
git.internal/re/tinyqueue v0.1.3 h1:4EKqZhzHLgoE7qp3+Jy4fLTJ+VXYdnREYiErcW6/Tds=
git.internal/re/tinyqueue v0.1.3/go.mod h1:xwfmZ1Jo/JI0eXLc78eGZv+kEtJipgyui683yVTh7fc=

View File

@ -4,13 +4,15 @@ import (
"math"
"sync"
"github.com/tidwall/rtred/base"
"git.internal/re/rtred/base"
)
type Iterator func(item Item) bool
type Item interface {
type (
Iterator func(item Item) bool
Item interface {
Rect(ctx interface{}) (min []float64, max []float64)
}
)
type RTree struct {
dims int
@ -85,12 +87,14 @@ func (tr *RTree) Remove(item Item) {
tr.used--
}
}
func (tr *RTree) Reset() {
for i := 0; i < len(tr.trs); i++ {
tr.trs[i] = nil
}
tr.used = 0
}
func (tr *RTree) Count() int {
var count int
for _, btr := range tr.trs {
@ -127,6 +131,7 @@ func (tr *RTree) Search(bounds Item, iter Iterator) {
}
}
}
func search(btr *base.RTree, min, max []float64, dims int, iter Iterator) bool {
amin := make([]float64, dims)
amax := make([]float64, dims)
@ -254,6 +259,7 @@ func (tr *RTree) KNN(bounds Item, center bool, iter func(item Item, dist float64
}
mu.Unlock()
}
func knn(btr *base.RTree, min, max []float64, center bool, dims int, iter func(item interface{}, dist float64) bool) bool {
amin := make([]float64, dims)
amax := make([]float64, dims)