@@ -607,16 +607,19 @@ HnswEntryCandidate(char *base, HnswElement entryPoint, Datum q, Relation index,
607
607
return hc ;
608
608
}
609
609
610
+ #define HnswGetPairingHeapCandidate (membername , ptr ) (pairingheap_container(HnswPairingHeapNode, membername, ptr)->inner)
611
+ #define HnswGetPairingHeapCandidateConst (membername , ptr ) (pairingheap_const_container(HnswPairingHeapNode, membername, ptr)->inner)
612
+
610
613
/*
611
614
* Compare candidate distances
612
615
*/
613
616
static int
614
617
CompareNearestCandidates (const pairingheap_node * a , const pairingheap_node * b , void * arg )
615
618
{
616
- if ((( const HnswPairingHeapNode * ) a )-> inner -> distance < (( const HnswPairingHeapNode * ) b ) -> inner -> distance )
619
+ if (HnswGetPairingHeapCandidateConst ( c_node , a )-> distance < HnswGetPairingHeapCandidateConst ( c_node , b ) -> distance )
617
620
return 1 ;
618
621
619
- if ((( const HnswPairingHeapNode * ) a )-> inner -> distance > (( const HnswPairingHeapNode * ) b ) -> inner -> distance )
622
+ if (HnswGetPairingHeapCandidateConst ( c_node , a )-> distance > HnswGetPairingHeapCandidateConst ( c_node , b ) -> distance )
620
623
return -1 ;
621
624
622
625
return 0 ;
@@ -628,10 +631,10 @@ CompareNearestCandidates(const pairingheap_node *a, const pairingheap_node *b, v
628
631
static int
629
632
CompareFurthestCandidates (const pairingheap_node * a , const pairingheap_node * b , void * arg )
630
633
{
631
- if ((( const HnswPairingHeapNode * ) a )-> inner -> distance < (( const HnswPairingHeapNode * ) b ) -> inner -> distance )
634
+ if (HnswGetPairingHeapCandidateConst ( w_node , a )-> distance < HnswGetPairingHeapCandidateConst ( w_node , b ) -> distance )
632
635
return -1 ;
633
636
634
- if ((( const HnswPairingHeapNode * ) a )-> inner -> distance > (( const HnswPairingHeapNode * ) b ) -> inner -> distance )
637
+ if (HnswGetPairingHeapCandidateConst ( w_node , a )-> distance > HnswGetPairingHeapCandidateConst ( w_node , b ) -> distance )
635
638
return 1 ;
636
639
637
640
return 0 ;
@@ -746,11 +749,13 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F
746
749
{
747
750
HnswCandidate * hc = (HnswCandidate * ) lfirst (lc2 );
748
751
bool found ;
752
+ HnswPairingHeapNode * node ;
749
753
750
754
AddToVisited (base , & v , hc , index , & found );
751
755
752
- pairingheap_add (C , & (CreatePairingHeapNode (hc )-> ph_node ));
753
- pairingheap_add (W , & (CreatePairingHeapNode (hc )-> ph_node ));
756
+ node = CreatePairingHeapNode (hc );
757
+ pairingheap_add (C , & node -> c_node );
758
+ pairingheap_add (W , & node -> w_node );
754
759
755
760
/*
756
761
* Do not count elements being deleted towards ef when vacuuming. It
@@ -764,8 +769,8 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F
764
769
while (!pairingheap_is_empty (C ))
765
770
{
766
771
HnswNeighborArray * neighborhood ;
767
- HnswCandidate * c = (( HnswPairingHeapNode * ) pairingheap_remove_first (C ))-> inner ;
768
- HnswCandidate * f = (( HnswPairingHeapNode * ) pairingheap_first (W ))-> inner ;
772
+ HnswCandidate * c = HnswGetPairingHeapCandidate ( c_node , pairingheap_remove_first (C ));
773
+ HnswCandidate * f = HnswGetPairingHeapCandidate ( w_node , pairingheap_first (W ));
769
774
HnswElement cElement ;
770
775
771
776
if (c -> distance > f -> distance )
@@ -801,7 +806,7 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F
801
806
HnswElement eElement = HnswPtrAccess (base , e -> element );
802
807
bool alwaysAdd = wlen < ef ;
803
808
804
- f = (( HnswPairingHeapNode * ) pairingheap_first (W ))-> inner ;
809
+ f = HnswGetPairingHeapCandidate ( w_node , pairingheap_first (W ));
805
810
806
811
if (index == NULL )
807
812
eDistance = GetCandidateDistance (base , e , q , procinfo , collation );
@@ -811,6 +816,7 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F
811
816
if (eDistance < f -> distance || alwaysAdd )
812
817
{
813
818
HnswCandidate * ec ;
819
+ HnswPairingHeapNode * node ;
814
820
815
821
Assert (!eElement -> deleted );
816
822
@@ -823,8 +829,9 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F
823
829
HnswPtrStore (base , ec -> element , eElement );
824
830
ec -> distance = eDistance ;
825
831
826
- pairingheap_add (C , & (CreatePairingHeapNode (ec )-> ph_node ));
827
- pairingheap_add (W , & (CreatePairingHeapNode (ec )-> ph_node ));
832
+ node = CreatePairingHeapNode (ec );
833
+ pairingheap_add (C , & node -> c_node );
834
+ pairingheap_add (W , & node -> w_node );
828
835
829
836
/*
830
837
* Do not count elements being deleted towards ef when
@@ -847,7 +854,7 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F
847
854
/* Add each element of W to w */
848
855
while (!pairingheap_is_empty (W ))
849
856
{
850
- HnswCandidate * hc = (( HnswPairingHeapNode * ) pairingheap_remove_first (W ))-> inner ;
857
+ HnswCandidate * hc = HnswGetPairingHeapCandidate ( w_node , pairingheap_remove_first (W ));
851
858
852
859
w = lappend (w , hc );
853
860
}
0 commit comments