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 ifa == 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.