Trait vpsearch::MetricSpace [] [src]

pub trait MetricSpace<UserImplementationType = ()> {
    type UserData;
    type Distance: Copy + PartialOrd + Bounded + Add<Output = Self::Distance>;
    fn distance(
        &self,
        other: &Self,
        user_data: &Self::UserData
    ) -> Self::Distance; }

Elements you're searching for must be comparable using this trait.

You can ignore UserImplementationType if you're implementing MetricSpace for your custom type. However, if you're implementing MetricSpace for a type from std or another crate, then you need to uniquely identify your implementation (that's because of Rust's Orphan Rules).

This example is not tested
impl MetricSpace for MyInt {/*…*/}

/// That dummy struct disambiguates between yours and everyone else's impl for a tuple:
struct MyXYCoordinates;
impl MetricSpace<MyXYCoordinates> for (f32,f32) {/*…*/}

Associated Types

This is used as a context for comparisons. Use () if the elements already contain all the data you need.

This is a fancy way of saying it should be f32 or u32

Required Methods

This function must return distance between two items that meets triangle inequality. Specifically, it can't return squared distance (you must use sqrt if you use Euclidean distance)

@param user_data Whatever you want. Passed from new_with_user_data_*()

Implementors