From 600ca5a7977accc31e13b1246e6b785666b9f01e Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 8 Aug 2023 18:22:55 -0700 Subject: [PATCH] Improved logic for pruning elements --- src/hnswutils.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hnswutils.c b/src/hnswutils.c index 3092144..a7bccc8 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -859,8 +859,8 @@ UpdateConnections(HnswElement element, List *neighbors, int m, int lc, List **up else hc3->distance = GetCandidateDistance(hc3, q, procinfo, collation); - /* Prune deleted element */ - if (hc3->element->deleted) + /* Prune element if being deleted */ + if (list_length(hc3->element->heaptids) == 0) { pruned = ¤tNeighbors->items[i]; break; @@ -868,14 +868,14 @@ UpdateConnections(HnswElement element, List *neighbors, int m, int lc, List **up } } - /* Add and sort candidates */ - for (int i = 0; i < currentNeighbors->length; i++) - c = lappend(c, ¤tNeighbors->items[i]); - c = lappend(c, &hc2); - list_sort(c, CompareCandidateDistances); - if (pruned == NULL) { + /* Add and sort candidates */ + for (int i = 0; i < currentNeighbors->length; i++) + c = lappend(c, ¤tNeighbors->items[i]); + c = lappend(c, &hc2); + list_sort(c, CompareCandidateDistances); + SelectNeighbors(c, m, lc, procinfo, collation, &pruned); /* Should not happen */