Move some code from insert() into Search

This commit is contained in:
Dirkjan Ochtman 2021-01-21 09:39:15 +01:00
parent 31f624be5c
commit 640592b411
1 changed files with 26 additions and 7 deletions

View File

@ -404,14 +404,16 @@ fn insert<P: Point>(
let &Candidate { distance, pid } = candidate;
if let Some(heuristic) = heuristic {
insertion.reset();
let candidate_point = &points[pid];
insertion.push(new, candidate_point, points);
for hop in layer.as_slice().nearest_iter(pid) {
insertion.push(hop, candidate_point, points);
}
let found = insertion.add_neighbor_heuristic(
new,
layer.as_slice().nearest_iter(pid),
layer,
M * 2,
&points[pid],
points,
*heuristic,
);
let found =
insertion.select_heuristic(&layer, M * 2, candidate_point, points, *heuristic);
layer[pid].rewrite(found.iter().map(|candidate| candidate.pid));
layer[new].set(i, pid);
} else {
@ -512,6 +514,23 @@ impl Search {
self.nearest.truncate(self.ef);
}
fn add_neighbor_heuristic<P: Point>(
&mut self,
new: PointId,
current: impl Iterator<Item = PointId>,
layer: &[ZeroNode],
num: usize,
point: &P,
points: &[P],
params: Heuristic,
) -> &[Candidate] {
self.push(new, point, points);
for pid in current {
self.push(pid, point, points);
}
self.select_heuristic(&layer, num, point, points, params)
}
fn select_heuristic<P: Point>(
&mut self,
layer: &[ZeroNode],