pgvector.git / summary / log / commit / refs
commit f7eda7bd20971dfca3227e3d2a6fdf227abac23e
Author: Andrew Kane <andrew@ankane.org>
Date: Thu Jan 25 01:54:33 2024 +0000
DRY neighbor array size [skip ci]
src/hnsw.h | 2 ++
src/hnswutils.c | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/hnsw.h b/src/hnsw.h
index dcd7d284..5531b4e5 100644
--- a/src/hnsw.h
+++ b/src/hnsw.h
@@ -64,6 +64,8 @@
#define HNSW_ELEMENT_TUPLE_SIZE(size) MAXALIGN(offsetof(HnswElementTupleData, data) + (size))
#define HNSW_NEIGHBOR_TUPLE_SIZE(level, m) MAXALIGN(offsetof(HnswNeighborTupleData, indextids) + ((level) + 2) * (m) * sizeof(ItemPointerData))
+#define HNSW_NEIGHBOR_ARRAY_SIZE(lm) (offsetof(HnswNeighborArray, items) + sizeof(HnswCandidate) * (lm))
+
#define HnswPageGetOpaque(page) ((HnswPageOpaque) PageGetSpecialPointer(page))
#define HnswPageGetMeta(page) ((HnswMetaPageData *) PageGetContents(page))
diff --git a/src/hnswutils.c b/src/hnswutils.c
index cdb5838a..f7c0029a 100644
--- a/src/hnswutils.c
+++ b/src/hnswutils.c
@@ -208,7 +208,7 @@ HnswInitPage(Buffer buf, Page page)
static HnswNeighborArray *
HnswInitNeighborArray(int lm, HnswAllocator * allocator)
{
- HnswNeighborArray *a = HnswAlloc(allocator, offsetof(HnswNeighborArray, items) + sizeof(HnswCandidate) * lm);
+ HnswNeighborArray *a = HnswAlloc(allocator, HNSW_NEIGHBOR_ARRAY_SIZE(lm));
a->length = 0;
a->closerSet = false;
@@ -734,7 +734,7 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F
/* Create local memory for neighborhood if needed */
if (index == NULL)
{
- neighborhoodSize = offsetof(HnswNeighborArray, items) + sizeof(HnswCandidate) * HnswGetLayerM(m, lc);
+ neighborhoodSize = HNSW_NEIGHBOR_ARRAY_SIZE(HnswGetLayerM(m, lc));
neighborhoodData = palloc(neighborhoodSize);
}
[parent: 2260e1331597]