Trait space::Knn[][src]

pub trait Knn<'a> {
    type Ix: Copy;
    type Point: 'a;
    type Value: 'a;
    type Metric: Metric<Self::Point>;
    type KnnIter: IntoIterator<Item = (Neighbor<<Self::Metric as Metric<Self::Point>>::Unit, Self::Ix>, &'a Self::Point, &'a Self::Value)>;
    fn point(&self, index: Self::Ix) -> &'a Self::Point;
fn value(&self, index: Self::Ix) -> &'a Self::Value;
fn knn(&'a self, query: &Self::Point, num: usize) -> Self::KnnIter;
fn nn(
        &'a self,
        query: &Self::Point
    ) -> Option<(Neighbor<<Self::Metric as Metric<Self::Point>>::Unit, Self::Ix>, &'a Self::Point, &'a Self::Value)>; }
Expand description

Implement this trait on data structures (or wrappers) which perform KNN searches. The data structure should maintain a key-value mapping between neighbour points and data values.

The lifetime on the trait will be removed once GATs are stabilized.

Associated Types

Required methods

Get a point using a neighbor index returned by Knn::knn or Knn::nn.

This should only be used directly after one of the mentioned methods are called to retrieve a point associated with a neighbor, and will panic if the index is incorrect due to mutating the data structure thereafter. The index is only valid up until the next mutation.

Get a value using a neighbor index returned by Knn::knn or Knn::nn.

This should only be used directly after one of the mentioned methods are called to retrieve a value associated with a neighbor, and will panic if the index is incorrect due to mutating the data structure thereafter. The index is only valid up until the next mutation.

Get num nearest neighbor keys and values of target.

For many KNN search algorithms, the returned neighbors are approximate, and may not be the actual nearest neighbors.

Get the nearest neighbor key and values of target.

For many KNN search algorithms, the returned neighbors are approximate, and may not be the actual nearest neighbors.

Implementors