pgvector.git / summary / log / commit / refs

commit    90e0a14bdad11296bbaec2b7e7a67f6823a22770
Author:   Andrew Kane <andrew@ankane.org>
Date:     Thu Jan 25 00:17:34 2024 +0000

    Moved allocating neighbor array to separate function [skip ci]


src/hnswutils.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/hnswutils.c b/src/hnswutils.c index 6e703636..1764c331 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -202,6 +202,19 @@ HnswInitPage(Buffer buf, Page page) HnswPageGetOpaque(page)->page_id = HNSW_PAGE_ID; } +/* + * Allocate a neighbor array + */ +static HnswNeighborArray * +HnswInitNeighborArray(int lm, HnswAllocator * allocator) +{ + HnswNeighborArray *a = HnswAlloc(allocator, offsetof(HnswNeighborArray, items) + sizeof(HnswCandidate) * lm); + + a->length = 0; + a->closerSet = false; + return a; +} + /* * Allocate neighbors */ @@ -216,14 +229,9 @@ HnswInitNeighbors(char *base, HnswElement element, int m, HnswAllocator * alloca for (int lc = 0; lc <= level; lc++) { - HnswNeighborArray *a; int lm = HnswGetLayerM(m, lc); - HnswPtrStore(base, neighborList[lc], (HnswNeighborArray *) HnswAlloc(allocator, offsetof(HnswNeighborArray, items) + sizeof(HnswCandidate) * lm)); - - a = HnswGetNeighbors(base, element, lc); - a->length = 0; - a->closerSet = false; + HnswPtrStore(base, neighborList[lc], HnswInitNeighborArray(lm, allocator)); } } [parent: c816b5d0d18c]