mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 23:26:55 +08:00
DRY code [skip ci]
This commit is contained in:
@@ -248,6 +248,7 @@ void HnswAddHeapTid(HnswElement element, ItemPointer heaptid);
|
|||||||
void HnswInitNeighbors(HnswElement element, int m);
|
void HnswInitNeighbors(HnswElement element, int m);
|
||||||
bool HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRel);
|
bool HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRel);
|
||||||
void HnswLoadElement(HnswElement element, float *distance, Datum *q, Relation index, FmgrInfo *procinfo, Oid collation, bool loadvec);
|
void HnswLoadElement(HnswElement element, float *distance, Datum *q, Relation index, FmgrInfo *procinfo, Oid collation, bool loadvec);
|
||||||
|
void HnswSetElementTuple(HnswElementTuple etup, HnswElement element);
|
||||||
|
|
||||||
/* Index access methods */
|
/* Index access methods */
|
||||||
IndexBuildResult *hnswbuild(Relation heap, Relation index, IndexInfo *indexInfo);
|
IndexBuildResult *hnswbuild(Relation heap, Relation index, IndexInfo *indexInfo);
|
||||||
|
|||||||
@@ -109,17 +109,8 @@ CreateElementPages(HnswBuildState * buildstate)
|
|||||||
e->neighborPage = neighborPage++;
|
e->neighborPage = neighborPage++;
|
||||||
|
|
||||||
/* Set item data */
|
/* Set item data */
|
||||||
for (int i = 0; i < HNSW_HEAPTIDS; i++)
|
HnswSetElementTuple(element, e);
|
||||||
{
|
|
||||||
if (i < list_length(e->heaptids))
|
|
||||||
element->heaptids[i] = *((ItemPointer) list_nth(e->heaptids, i));
|
|
||||||
else
|
|
||||||
ItemPointerSetInvalid(&element->heaptids[i]);
|
|
||||||
}
|
|
||||||
element->level = e->level;
|
|
||||||
element->deleted = 0;
|
|
||||||
element->neighborPage = e->neighborPage;
|
element->neighborPage = e->neighborPage;
|
||||||
memcpy(&element->vec, e->vec, VECTOR_SIZE(dimensions));
|
|
||||||
|
|
||||||
/* Ensure free space */
|
/* Ensure free space */
|
||||||
if (PageGetFreeSpace(page) < elementsz)
|
if (PageGetFreeSpace(page) < elementsz)
|
||||||
|
|||||||
@@ -80,12 +80,7 @@ WriteNewElementPages(Relation index, HnswElement e, int m)
|
|||||||
|
|
||||||
/* Prepare tuple */
|
/* Prepare tuple */
|
||||||
etup = palloc0(esize);
|
etup = palloc0(esize);
|
||||||
etup->heaptids[0] = *((ItemPointer) linitial(e->heaptids));
|
HnswSetElementTuple(etup, e);
|
||||||
for (int i = 1; i < HNSW_HEAPTIDS; i++)
|
|
||||||
ItemPointerSetInvalid(&etup->heaptids[i]);
|
|
||||||
etup->level = e->level;
|
|
||||||
etup->deleted = 0;
|
|
||||||
memcpy(&etup->vec, e->vec, VECTOR_SIZE(dimensions));
|
|
||||||
|
|
||||||
/* Find a page to insert the item */
|
/* Find a page to insert the item */
|
||||||
for (;;)
|
for (;;)
|
||||||
|
|||||||
@@ -602,6 +602,24 @@ HnswFreeElement(HnswElement element)
|
|||||||
pfree(element);
|
pfree(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set element tuple, except for neighbor page
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
HnswSetElementTuple(HnswElementTuple etup, HnswElement element)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < HNSW_HEAPTIDS; i++)
|
||||||
|
{
|
||||||
|
if (i < list_length(element->heaptids))
|
||||||
|
etup->heaptids[i] = *((ItemPointer) list_nth(element->heaptids, i));
|
||||||
|
else
|
||||||
|
ItemPointerSetInvalid(&etup->heaptids[i]);
|
||||||
|
}
|
||||||
|
etup->level = element->level;
|
||||||
|
etup->deleted = 0;
|
||||||
|
memcpy(&etup->vec, element->vec, VECTOR_SIZE(element->vec->dim));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the distance for a candidate
|
* Get the distance for a candidate
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user