Revert "Replaced pairing heap with array in SelectNeighbors - closes #447"

This reverts commit 14b278dec9.
This commit is contained in:
Andrew Kane
2024-02-28 11:33:14 -08:00
parent 14b278dec9
commit efed873a3e

View File

@@ -952,9 +952,7 @@ SelectNeighbors(char *base, List *c, int lm, int lc, FmgrInfo *procinfo, Oid col
{ {
List *r = NIL; List *r = NIL;
List *w = list_copy(c); List *w = list_copy(c);
HnswCandidate **wd; pairingheap *wd;
int wdlen = 0;
int wdoff = 0;
HnswNeighborArray *neighbors = HnswGetNeighbors(base, e2, lc); HnswNeighborArray *neighbors = HnswGetNeighbors(base, e2, lc);
bool mustCalculate = !neighbors->closerSet; bool mustCalculate = !neighbors->closerSet;
List *added = NIL; List *added = NIL;
@@ -963,7 +961,7 @@ SelectNeighbors(char *base, List *c, int lm, int lc, FmgrInfo *procinfo, Oid col
if (list_length(w) <= lm) if (list_length(w) <= lm)
return w; return w;
wd = palloc(sizeof(HnswCandidate *) * list_length(w)); wd = pairingheap_allocate(CompareNearestCandidates, NULL);
/* Ensure order of candidates is deterministic for closer caching */ /* Ensure order of candidates is deterministic for closer caching */
if (sortCandidates) if (sortCandidates)
@@ -1029,21 +1027,21 @@ SelectNeighbors(char *base, List *c, int lm, int lc, FmgrInfo *procinfo, Oid col
if (e->closer) if (e->closer)
r = lappend(r, e); r = lappend(r, e);
else else
wd[wdlen++] = e; pairingheap_add(wd, &(CreatePairingHeapNode(e)->ph_node));
} }
/* Cached value can only be used in future if sorted deterministically */ /* Cached value can only be used in future if sorted deterministically */
neighbors->closerSet = sortCandidates; neighbors->closerSet = sortCandidates;
/* Keep pruned connections */ /* Keep pruned connections */
while (wdoff < wdlen && list_length(r) < lm) while (!pairingheap_is_empty(wd) && list_length(r) < lm)
r = lappend(r, wd[wdoff++]); r = lappend(r, ((HnswPairingHeapNode *) pairingheap_remove_first(wd))->inner);
/* Return pruned for update connections */ /* Return pruned for update connections */
if (pruned != NULL) if (pruned != NULL)
{ {
if (wdoff < wdlen) if (!pairingheap_is_empty(wd))
*pruned = wd[wdoff]; *pruned = ((HnswPairingHeapNode *) pairingheap_first(wd))->inner;
else else
*pruned = linitial(w); *pruned = linitial(w);
} }