Skip to content

Commit

Permalink
Update modules
Browse files Browse the repository at this point in the history
  • Loading branch information
minkezhang committed Oct 20, 2022
1 parent 284b61e commit 5b5b435
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/downflux/go-kd
go 1.19

require (
github.com/downflux/go-geometry v0.10.2
github.com/downflux/go-pq v0.1.4
github.com/google/go-cmp v0.5.8
github.com/downflux/go-geometry v0.13.0
github.com/downflux/go-pq v0.3.0
github.com/google/go-cmp v0.5.9
github.com/kyroy/kdtree v0.0.0-20200419114247-70830f883f1d
)

Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/downflux/go-geometry v0.10.2 h1:Z79Khzl6AKMSMLnM5xG75fEOL1fmIWlF14+8j+r01D0=
github.com/downflux/go-geometry v0.10.2/go.mod h1:XWTzSaMiRMAxupAR+cXAsa1Q75TCSp1Shc/ydsJ0xVE=
github.com/downflux/go-geometry v0.13.0 h1:MWGPpr9ZLMPh/oQLYWwHQG6LpM7KLKn8pfkxIzGFCbw=
github.com/downflux/go-geometry v0.13.0/go.mod h1:ZJcto0QwYRdoIbi5G4mh5y6v2xUS+d++/cANaO1F9+8=
github.com/downflux/go-pq v0.1.4 h1:SHFeyU+DNtx6gcsmBYPx+EekKIsmib8k7U39UGpH/7g=
github.com/downflux/go-pq v0.1.4/go.mod h1:vkc6UAQ+TBoNdTwDm5akDexE1auN2kQcR8BFw3hNCiM=
github.com/downflux/go-pq v0.3.0 h1:oWLx7rzsD4fv1f2kp33NUq63CJVQvXZORkcpHr6bp9g=
github.com/downflux/go-pq v0.3.0/go.mod h1:vkc6UAQ+TBoNdTwDm5akDexE1auN2kQcR8BFw3hNCiM=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jupp0r/go-priority-queue v0.0.0-20160601094913-ab1073853bde h1:+5PMaaQtDUwOcJIUlmX89P0J3iwTvErTmyn5WghzXAQ=
github.com/jupp0r/go-priority-queue v0.0.0-20160601094913-ab1073853bde/go.mod h1:RDgD/dfPmIwFH0qdUOjw71HjtWg56CtyLIoHL+R1wJw=
github.com/kyroy/kdtree v0.0.0-20200419114247-70830f883f1d h1:1n5M/49q9H6QtNJiiVL/W5mqgT1UdlGQ7oLP+DkJ1vs=
Expand Down
18 changes: 11 additions & 7 deletions internal/knn/knn.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,31 @@ func path[T point.P](n node.N[T], p vnd.V) []node.N[T] {
}

func KNN[T point.P](n node.N[T], p vnd.V, k int, f func(p T) bool) []T {
q := pq.New[T](k)
knn(n, p, q, vnd.V(make([]float64, p.Dimension())), f)
q := pq.New[T](k, pq.PMax)
knn(n, p, q, vnd.M(make([]float64, p.Dimension())), f)

ps := make([]T, q.Len())
for i := q.Len() - 1; i >= 0; i-- {
ps[i] = q.Pop()
ps[i], _ = q.Pop()
}
return ps
}

func knn[T point.P](n node.N[T], p vnd.V, q *pq.PQ[T], buf vnd.V, f func(p T) bool) {
func knn[T point.P](n node.N[T], p vnd.V, q *pq.PQ[T], buf vnd.M, f func(p T) bool) {
for _, n := range path[T](n, p) {
for _, datum := range n.Data() {
vnd.SubBuf(p, datum.P(), buf)
if d := vnd.SquaredMagnitude(buf); (!q.Full() || d < q.Priority()) && f(datum) {
buf.Copy(p)
buf.Sub(datum.P())

if d := vnd.SquaredMagnitude(buf.V()); (!q.Full() || d < q.Priority()) && f(datum) {
q.Push(datum, d)
}
}

if !n.Leaf() {
vnd.SubBuf(p, n.Pivot(), buf)
buf.Copy(p)
buf.Sub(n.Pivot())

if q.Priority() > math.Pow(buf.X(n.Axis()), 2) {
if vector.Comparator(n.Axis()).Less(p, n.Pivot()) {
knn(n.R(), p, q, buf, f)
Expand Down
2 changes: 1 addition & 1 deletion internal/rangesearch/rangesearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func RangeSearch[T point.P](n node.N[T], q hyperrectangle.R, f func(p T) bool) [
}

func rangesearch[T point.P](n node.N[T], q hyperrectangle.R, bound hyperrectangle.R, f func(p T) bool) []T {
if _, ok := q.Intersect(bound); n.Nil() || !ok {
if n.Nil() || hyperrectangle.Disjoint(q, bound) {
return nil
}

Expand Down

0 comments on commit 5b5b435

Please sign in to comment.