Trait Metric

Source
pub trait Metric<K: ?Sized> {
    // Required methods
    fn distance(&self, a: &K, b: &K) -> u32;
    fn threshold_distance(&self, a: &K, b: &K, threshold: u32) -> Option<u32>;
}
Expand description

A trait for a metric (distance function).

Implementations should follow the metric axioms:

  • Zero: distance(a, b) == 0 if and only if a == b
  • Symmetry: distance(a, b) == distance(b, a)
  • Triangle inequality: distance(a, c) <= distance(a, b) + distance(b, c)

If any of these rules are broken, then the BK-tree may give unexpected results.

Required Methods§

Source

fn distance(&self, a: &K, b: &K) -> u32

Source

fn threshold_distance(&self, a: &K, b: &K, threshold: u32) -> Option<u32>

Implementors§