[−][src]Trait vpsearch::MetricSpace
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
type UserData
This is used as a context for comparisons. Use ()
if the elements already contain all the data you need.
type Distance: Copy + PartialOrd + Bounded + Add<Output = Self::Distance>
This is a fancy way of saying it should be f32
or u32
Required methods
fn distance(&self, other: &Self, user_data: &Self::UserData) -> Self::Distance
This function must return distance between two items that meets triangle inequality. Specifically, it MUST NOT return a squared distance (you must use sqrt if you use Euclidean distance)
user_data
—Whatever you want. Passed fromnew_with_user_data_*()