vpsearch

Trait BestCandidate

Source
pub trait BestCandidate<Item: MetricSpace<Impl> + Clone, Impl>
where Self: Sized,
{ type Output; // Required methods 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; }
Expand description

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

struct Impl;
struct ReturnByIndex<I: MetricSpace<Impl>> {
   distance: I::Distance,
   idx: usize,
}

impl<Item: MetricSpace<Impl> + Clone> 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)
    }
}

Required Associated Types§

Source

type Output

find_nearest() will return this type

Required Methods§

Source

fn consider( &mut self, item: &Item, distance: Item::Distance, candidate_index: usize, user_data: &Item::UserData, )

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.

Source

fn distance(&self) -> Item::Distance

Minimum distance seen so far

Source

fn result(self, user_data: &Item::UserData) -> Self::Output

Called once after all relevant nodes in the tree were visited

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§