Make selection phase explicit in the code
This commit is contained in:
parent
19e451bac2
commit
09dd8d886b
10
src/lib.rs
10
src/lib.rs
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue