Documentation ¶
Overview ¶
Package vp provides vantage point trees (VP-trees), a spatial index structure.
Package vp provides vantage point trees (VP-trees), a spatial index structure.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metric ¶
A Metric is a function m that satisfies the metric axioms.
It is assumed that a metric can be called by multiple goroutines concurrently.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
A Tree is an index structure for strings that allows nearest-neighbor and radius queries.
func New ¶
New constructs a Tree from the points, using the metric m.
Construction may be stopped by canceling ctx, in which case ctx.Err() is returned. Otherwise, err will be nil. If ctx is nil, context.Background() is used.
func NewFromSeed ¶
NewFrom is like New, but with an explicit random seed.
func (*Tree) Do ¶
Do calls f on each item in the tree t, in some unspecified order, until f returns false.
func (*Tree) Search ¶
func (t *Tree) Search(ctx context.Context, p string, k int, maxDist float64, pred Predicate) ([]Result, error)
Search performs a generalized nearest neighbors search. It returns the k points within t that are nearest to p, after eliminating all points farther than maxDist and all points for which pred returns false.
The returned points are sorted by distance from p, so the nearest neighbor is at index 0.
To do a regular nearest neighbors search, set maxDist to math.Inf(+1).
Search returns an error if and only if the context ctx expires. If ctx is nil, context.Background() is used instead. If pred is nil, a function that always returns true is used instead.