Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit124018b

Browse files
committed
Added HnswInitSearchCandidate function
1 parent35b252a commit124018b

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

‎src/hnswutils.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -581,21 +581,34 @@ GetElementDistance(char *base, HnswElement element, HnswQuery * q, HnswSupport *
581581
returnHnswGetDistance(q->value,value,support);
582582
}
583583

584+
/*
585+
* Allocate a search candidate
586+
*/
587+
staticHnswSearchCandidate*
588+
HnswInitSearchCandidate(char*base,HnswElementelement,doubledistance)
589+
{
590+
HnswSearchCandidate*sc=palloc(sizeof(HnswSearchCandidate));
591+
592+
HnswPtrStore(base,sc->element,element);
593+
sc->distance=distance;
594+
returnsc;
595+
}
596+
584597
/*
585598
* Create a candidate for the entry point
586599
*/
587600
HnswSearchCandidate*
588601
HnswEntryCandidate(char*base,HnswElemententryPoint,HnswQuery*q,Relationindex,HnswSupport*support,boolloadVec)
589602
{
590-
HnswSearchCandidate*sc=palloc(sizeof(HnswSearchCandidate));
591603
boolinMemory=index==NULL;
604+
doubledistance;
592605

593-
HnswPtrStore(base,sc->element,entryPoint);
594606
if (inMemory)
595-
sc->distance=GetElementDistance(base,entryPoint,q,support);
607+
distance=GetElementDistance(base,entryPoint,q,support);
596608
else
597-
HnswLoadElement(entryPoint,&sc->distance,q,index,support,loadVec,NULL);
598-
returnsc;
609+
HnswLoadElement(entryPoint,&distance,q,index,support,loadVec,NULL);
610+
611+
returnHnswInitSearchCandidate(base,entryPoint,distance);
599612
}
600613

601614
/*
@@ -912,9 +925,7 @@ HnswSearchLayer(char *base, HnswQuery * q, List *ep, int ef, int lc, Relation in
912925
if (discarded!=NULL)
913926
{
914927
/* Create a new candidate */
915-
e=palloc(sizeof(HnswSearchCandidate));
916-
HnswPtrStore(base,e->element,eElement);
917-
e->distance=eDistance;
928+
e=HnswInitSearchCandidate(base,eElement,eDistance);
918929
pairingheap_add(*discarded,&e->w_node);
919930
}
920931

@@ -926,9 +937,7 @@ HnswSearchLayer(char *base, HnswQuery * q, List *ep, int ef, int lc, Relation in
926937
continue;
927938

928939
/* Create a new candidate */
929-
e=palloc(sizeof(HnswSearchCandidate));
930-
HnswPtrStore(base,e->element,eElement);
931-
e->distance=eDistance;
940+
e=HnswInitSearchCandidate(base,eElement,eDistance);
932941
pairingheap_add(C,&e->c_node);
933942
pairingheap_add(W,&e->w_node);
934943

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp