Trait vpsearch::BestCandidate [] [src]

pub trait BestCandidate<Item: MetricSpace<Impl> + Copy, Impl> where
    Self: Sized
{ type Output; fn consider(
        &mut self,
        item: &Item,
        distance: Item::Distance,
        candidate_index: usize,
        user_data: &Item::UserData
    );
fn distance(&self) -> Item::Distance;
fn result(self, user_data: &Item::UserData) -> Self::Output; }

You can implement this if you want to peek at all visited elements

This example is not tested
impl<Item: MetricSpace<Impl> + Copy> BestCandidate<Item, Impl> for ReturnByIndex<Item> {
    type Output = (usize, Item::Distance);

    fn consider(&mut self, _: &Item, distance: Item::Distance, candidate_index: usize, _: &Item::UserData) {
        if distance < self.distance {
            self.distance = distance;
            self.idx = candidate_index;
        }
    }
    fn distance(&self) -> Item::Distance {
        self.distance
    }
    fn result(self, _: &Item::UserData) -> Self::Output {
        (self.idx, self.distance)
    }
}

Associated Types

find_nearest() will return this type

Required Methods

This is a visitor method. If the given distance is smaller than previously seen, keep the item (or its index). UserData is the same as for MetricSpace<Impl>, and it's () by default.

Minimum distance seen so far

Called once after all relevant nodes in the tree were visited

Implementors