From c03cec44584a0751ddf509efe696a20c921642d4 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 19 Jan 2021 10:47:35 +0100 Subject: [PATCH] Fix neighbor updates for heuristic searches --- src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c3bc93f..c8fcf69 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -393,9 +393,16 @@ fn insert( let found = insertion.select_heuristic(&layer, M * 2, candidate_point, points, *heuristic); - for (slot, hop) in layer[pid].nearest.iter_mut().zip(found) { - *slot = hop.pid; + for (i, slot) in layer[pid].nearest.iter_mut().enumerate() { + if let Some(&Candidate { pid, .. }) = found.get(i) { + *slot = pid; + } else if *slot != PointId::invalid() { + *slot = PointId::invalid(); + } else { + break; + } } + layer[new].nearest[i] = pid; } else { // Find the correct index to insert at to keep the neighbor's neighbors sorted