Simplify creation of search result iterator

This commit is contained in:
Dirkjan Ochtman 2021-03-17 16:43:43 +01:00
parent 28d18d451e
commit 1950ca2b3b
1 changed files with 7 additions and 7 deletions

View File

@ -330,16 +330,12 @@ where
point: &P, point: &P,
search: &'a mut Search, search: &'a mut Search,
) -> impl Iterator<Item = PointId> + ExactSizeIterator + 'a { ) -> impl Iterator<Item = PointId> + ExactSizeIterator + 'a {
fn map(candidate: &Candidate) -> PointId { search.reset();
candidate.pid
}
if self.points.is_empty() { if self.points.is_empty() {
return (&[] as &[Candidate]).iter().map(map); return search.iter();
} }
search.visited.reserve_capacity(self.points.len()); search.visited.reserve_capacity(self.points.len());
search.reset();
search.push(PointId(0), point, &self.points); search.push(PointId(0), point, &self.points);
for cur in LayerId(self.layers.len()).descend() { for cur in LayerId(self.layers.len()).descend() {
let (ef, num) = match cur.is_zero() { 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 /// Iterate over the keys and values in this index
@ -673,6 +669,10 @@ impl Search {
fn select_simple(&mut self) -> &[Candidate] { fn select_simple(&mut self) -> &[Candidate] {
&self.nearest &self.nearest
} }
fn iter(&self) -> impl Iterator<Item = PointId> + ExactSizeIterator + '_ {
self.nearest.iter().map(|candidate| candidate.pid)
}
} }
impl Default for Search { impl Default for Search {