vp

package
v0.0.0-...-ee75913 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

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

type Metric func(a, b string) float64

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 Predicate

type Predicate func(string) bool

type Result

type Result struct {
	Dist  float64 `json:"distance"`
	Point string  `json:"point"`
}

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

func New(ctx context.Context, m Metric, points []string) (t *Tree, err error)

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

func NewFromSeed(ctx context.Context, m Metric, points []string, seed int64) (t *Tree, err error)

NewFrom is like New, but with an explicit random seed.

func (*Tree) Do

func (t *Tree) Do(f func(string) bool)

Do calls f on each item in the tree t, in some unspecified order, until f returns false.

func (*Tree) Len

func (t *Tree) Len() int

Len reports the number of elements in t.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL