From 1950ca2b3ba4f343eaace1131722fb285848765b Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 17 Mar 2021 16:43:43 +0100 Subject: [PATCH] Simplify creation of search result iterator --- instant-distance/src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/instant-distance/src/lib.rs b/instant-distance/src/lib.rs index 9961c13..59baf42 100644 --- a/instant-distance/src/lib.rs +++ b/instant-distance/src/lib.rs @@ -330,16 +330,12 @@ where point: &P, search: &'a mut Search, ) -> impl Iterator + ExactSizeIterator + 'a { - fn map(candidate: &Candidate) -> PointId { - candidate.pid - } - + search.reset(); if self.points.is_empty() { - return (&[] as &[Candidate]).iter().map(map); + return search.iter(); } search.visited.reserve_capacity(self.points.len()); - search.reset(); search.push(PointId(0), point, &self.points); for cur in LayerId(self.layers.len()).descend() { let (ef, num) = match cur.is_zero() { @@ -358,7 +354,7 @@ where } } - search.select_simple().iter().map(map) + search.iter() } /// Iterate over the keys and values in this index @@ -673,6 +669,10 @@ impl Search { fn select_simple(&mut self) -> &[Candidate] { &self.nearest } + + fn iter(&self) -> impl Iterator + ExactSizeIterator + '_ { + self.nearest.iter().map(|candidate| candidate.pid) + } } impl Default for Search {