mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-09 22:30:58 +08:00
Moved allocating neighbor array to separate function [skip ci]
This commit is contained in:
@@ -202,6 +202,19 @@ HnswInitPage(Buffer buf, Page page)
|
|||||||
HnswPageGetOpaque(page)->page_id = HNSW_PAGE_ID;
|
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
|
* Allocate neighbors
|
||||||
*/
|
*/
|
||||||
@@ -216,14 +229,9 @@ HnswInitNeighbors(char *base, HnswElement element, int m, HnswAllocator * alloca
|
|||||||
|
|
||||||
for (int lc = 0; lc <= level; lc++)
|
for (int lc = 0; lc <= level; lc++)
|
||||||
{
|
{
|
||||||
HnswNeighborArray *a;
|
|
||||||
int lm = HnswGetLayerM(m, lc);
|
int lm = HnswGetLayerM(m, lc);
|
||||||
|
|
||||||
HnswPtrStore(base, neighborList[lc], (HnswNeighborArray *) HnswAlloc(allocator, offsetof(HnswNeighborArray, items) + sizeof(HnswCandidate) * lm));
|
HnswPtrStore(base, neighborList[lc], HnswInitNeighborArray(lm, allocator));
|
||||||
|
|
||||||
a = HnswGetNeighbors(base, element, lc);
|
|
||||||
a->length = 0;
|
|
||||||
a->closerSet = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user