Make selection phase explicit in the code

This commit is contained in:
Dirkjan Ochtman 2021-01-11 12:38:40 +01:00
parent 19e451bac2
commit 09dd8d886b
1 changed files with 7 additions and 3 deletions

View File

@ -233,10 +233,8 @@ where
for added in done.iter().copied() {
search.push(added, &points[pid], &points);
}
// Because we've added new points, we need to sort the nearest neighbors
search.nearest.sort_unstable();
insert(&mut zero, pid, &search.nearest, &points);
insert(&mut zero, pid, search.select_simple(num), &points);
done.push(pid);
pool.push(search);
}
@ -478,6 +476,12 @@ impl Search {
nearest.clear();
}
/// Selection of neighbors for insertion (algorithm 3 from the paper)
fn select_simple(&mut self, num: usize) -> &[Candidate] {
self.nearest.sort_unstable();
&self.nearest[..min(self.nearest.len(), num)]
}
/// Track node `pid` as a potential new neighbor for the given `point`
///
/// Will immediately return if the node has been considered before. This implements