diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-07-06 22:24:02 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-07-06 22:33:10 -0400 |
commit | 5f85a59d4be37d350bcf1ee62c25ac1f84d71770 (patch) | |
tree | 8fc7ea8e59226c5e677d7b9aef39b0b2be5f28b7 /src/chebyshev.rs | |
parent | ed4d7b7143f1a8a9602698ca3e60e18bbb4dd226 (diff) | |
download | acap-5f85a59d4be37d350bcf1ee62c25ac1f84d71770.tar.xz |
kd: Use a more traditional k-d tree implementation
The slight extra pruning possible in the previous implementation didn't
seem to be worth it. The new, simpler implementation is also about 30%
faster in most of the benchmarks.
This gets rid of Coordinate{Proximity,Metric} as they're not necessary
any more (and the old ExactNeighbors impl was too restrictive anyway).
Diffstat (limited to 'src/chebyshev.rs')
-rw-r--r-- | src/chebyshev.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/chebyshev.rs b/src/chebyshev.rs index f6eba8a..a01b24f 100644 --- a/src/chebyshev.rs +++ b/src/chebyshev.rs @@ -1,7 +1,8 @@ //! [Chebyshev distance](https://en.wikipedia.org/wiki/Chebyshev_distance). -use crate::coords::{CoordinateMetric, CoordinateProximity, Coordinates}; +use crate::coords::Coordinates; use crate::distance::{Metric, Proximity}; +use crate::lp::Minkowski; use num_traits::{zero, Signed}; @@ -104,15 +105,12 @@ impl<T: Coordinates> Metric<T> for Chebyshev<T> {} impl<T: Coordinates> Metric<Chebyshev<T>> for T {} -impl<T: Coordinates> CoordinateProximity<T::Value> for Chebyshev<T> { - type Distance = T::Value; +/// Chebyshev distance is a [Minkowski] distance. +impl<T: Coordinates> Minkowski for Chebyshev<T> {} - fn distance_to_coords(&self, coords: &[T::Value]) -> Self::Distance { - chebyshev_distance(self, coords) - } -} +impl<T: Coordinates> Minkowski<T> for Chebyshev<T> {} -impl<T: Coordinates> CoordinateMetric<T::Value> for Chebyshev<T> {} +impl<T: Coordinates> Minkowski<Chebyshev<T>> for T {} #[cfg(test)] mod tests { |