10000 Improved SelectNeighbors signature [skip ci] · postgrespro/pgvector@7ba593c · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ba593c

Browse files
committed
Improved SelectNeighbors signature [skip ci]
1 parent 525e3b8 commit 7ba593c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/hnswutils.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,14 +959,14 @@ CheckElementCloser(char *base, HnswCandidate * e, List *r, FmgrInfo *procinfo, O
959959
* Algorithm 4 from paper
960960
*/
961961
static List *
962-
SelectNeighbors(char *base, List *c, int lm, FmgrInfo *procinfo, Oid collation, HnswNeighborArray * neighbors, HnswCandidate * newCandidate, HnswCandidate * *pruned, bool sortCandidates)
962+
SelectNeighbors(char *base, List *c, int lm, FmgrInfo *procinfo, Oid collation, bool *closerSet, HnswCandidate * newCandidate, HnswCandidate * *pruned, bool sortCandidates)
963963
{
964964
List *r = NIL;
965965
List *w = list_copy(c);
966966
HnswCandidate **wd;
967967
int wdlen = 0;
968968
int wdoff = 0;
969-
bool mustCalculate = !neighbors->closerSet;
969+
bool mustCalculate = !(*closerSet);
970970
List *added = NIL;
971971
bool removedAny = false;
972972

@@ -1043,7 +1043,7 @@ SelectNeighbors(char *base, List *c, int lm, FmgrInfo *procinfo, Oid collation,
10431043
}
10441044

10451045
/* Cached value can only be used in future if sorted deterministically */
1046-
neighbors->closerSet = sortCandidates;
1046+
*closerSet = sortCandidates;
10471047

10481048
/* Keep pruned connections */
10491049
while (wdoff < wdlen && list_length(r) < lm)
@@ -1104,7 +1104,7 @@ HnswUpdateConnection(char *base, HnswNeighborArray * neighbors, HnswElement newE
11041104
c = lappend(c, &neighbors->items[i]);
11051105
c = lappend(c, &newHc);
11061106

1107-
SelectNeighbors(base, c, lm, procinfo, collation, neighbors, &newHc, &pruned, true);
1107+
SelectNeighbors(base, c, lm, procinfo, collation, &neighbors->closerSet, &newHc, &pruned, true);
11081108

11091109
/* Should not happen */
11101110
if (pruned == NULL)
@@ -1242,7 +1242,7 @@ HnswFindElementNeighbors(char *base, HnswElement element, HnswElement entryPoint
12421242
* sortCandidates to true for in-memory builds to enable closer
12431243
* caching, but there does not seem to be a difference in performance.
12441244
*/
1245-
neighbors = SelectNeighbors(base, lw, lm, procinfo, collation, HnswGetNeighbors(base, element, lc), NULL, NULL, false);
1245+
neighbors = SelectNeighbors(base, lw, lm, procinfo, collation, &HnswGetNeighbors(base, element, lc)->closerSet, NULL, NULL, false);
12461246

12471247
AddConnections(base, element, neighbors, lc);
12481248

0 commit comments

Comments
 (0)
0