From 49be082296367f90ca717a6cd4100d57823d8b78 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 27 Jun 2020 17:44:36 -0400 Subject: Fix some clippy lints --- src/kd.rs | 6 ++++++ src/vp.rs | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/kd.rs b/src/kd.rs index 2a9ecb4..c29dd80 100644 --- a/src/kd.rs +++ b/src/kd.rs @@ -251,6 +251,12 @@ impl KdTree { } } +impl Default for KdTree { + fn default() -> Self { + Self::new() + } +} + impl Extend for KdTree { fn extend>(&mut self, items: I) { if self.root.is_some() { diff --git a/src/vp.rs b/src/vp.rs index a71e942..3d88937 100644 --- a/src/vp.rs +++ b/src/vp.rs @@ -1,6 +1,6 @@ //! [Vantage-point trees](https://en.wikipedia.org/wiki/Vantage-point_tree). -use crate::distance::{DistanceValue, Metric, Proximity}; +use crate::distance::{Distance, DistanceValue, Metric, Proximity}; use crate::util::Ordered; use crate::{ExactNeighbors, NearestNeighbors, Neighborhood}; @@ -51,11 +51,11 @@ impl VpNode { fn balanced_recursive(nodes: &mut [Option>]) -> Option> { if let Some((node, children)) = nodes.split_first_mut() { let mut node = node.take().unwrap(); - children.sort_by_cached_key(|x| Ordered::new(Self::box_distance(&node, x))); + children.sort_by_cached_key(|x| Ordered::new(node.distance_to_box(x))); let (inside, outside) = children.split_at_mut(children.len() / 2); if let Some(last) = inside.last() { - node.radius = Self::box_distance(&node, last).into(); + node.radius = node.distance_to_box(last).value(); } node.inside = Self::balanced_recursive(inside); @@ -68,8 +68,8 @@ impl VpNode { } /// Get the distance between to boxed nodes. - fn box_distance(node: &Box, child: &Option>) -> T::Distance { - node.item.distance(&child.as_ref().unwrap().item) + fn distance_to_box(&self, child: &Option>) -> T::Distance { + self.item.distance(&child.as_ref().unwrap().item) } /// Push a new item into this subtree. @@ -255,6 +255,12 @@ where } } +impl Default for VpTree { + fn default() -> Self { + Self::new() + } +} + impl Extend for VpTree { fn extend>(&mut self, items: I) { if self.root.is_some() { -- cgit v1.2.3