@@ -400,41 +400,44 @@ TNearestItem = record
400400
401401 Delta := This^.Split.Vector[Axis] - Vector[Axis];
402402
403- if Length(Heap) < K then
404- DistSq := Self.SqDistance(This^.Split.Vector, Vector, High(UInt32)) // No limit if heap is not full
405- else
406- DistSq := Self.SqDistance(This^.Split.Vector, Vector, Heap[0 ].DistSq); // Limit is the furthest distance in the heap
407-
408- if not ((DistSq = 0 ) and NotEqual) then
403+ if not This^.Hidden then
409404 begin
410- if Length(Heap) < K then
411- begin
412- // heap not full, add current node
413- SetLength(Heap, Length(Heap) + 1 );
414- Heap[High(Heap)].Node := This;
415- Heap[High(Heap)].DistSq := DistSq;
416-
417- // heapify upwards
418- i := High(Heap);
419- while (i > 0 ) and (Heap[(i - 1 ) div 2 ].DistSq < Heap[i].DistSq) do
420- begin
421- Temp := Heap[i];
422- Heap[i] := Heap[(i - 1 ) div 2 ];
423- Heap[(i - 1 ) div 2 ] := Temp;
424- i := (i - 1 ) div 2 ;
425- end ;
426- end
427- else
428- begin
429- if DistSq < Heap[0 ].DistSq then
430- begin
431- // replace the furthest node with the current node
432- Heap[0 ].Node := This;
433- Heap[0 ].DistSq := DistSq;
434- // heapify downwards
435- Heapify(0 );
436- end ;
437- end ;
405+ if Length(Heap) < K then
406+ DistSq := Self.SqDistance(This^.Split.Vector, Vector, High(UInt32)) // No limit if heap is not full
407+ else
408+ DistSq := Self.SqDistance(This^.Split.Vector, Vector, Heap[0 ].DistSq); // Limit is the furthest distance in the heap
409+
410+ if not ((DistSq = 0 ) and NotEqual) then
411+ begin
412+ if Length(Heap) < K then
413+ begin
414+ // heap not full, add current node
415+ SetLength(Heap, Length(Heap) + 1 );
416+ Heap[High(Heap)].Node := This;
417+ Heap[High(Heap)].DistSq := DistSq;
418+
419+ // heapify upwards
420+ i := High(Heap);
421+ while (i > 0 ) and (Heap[(i - 1 ) div 2 ].DistSq < Heap[i].DistSq) do
422+ begin
423+ Temp := Heap[i];
424+ Heap[i] := Heap[(i - 1 ) div 2 ];
425+ Heap[(i - 1 ) div 2 ] := Temp;
426+ i := (i - 1 ) div 2 ;
427+ end ;
428+ end
429+ else
430+ begin
431+ if DistSq < Heap[0 ].DistSq then
432+ begin
433+ // replace the furthest node with the current node
434+ Heap[0 ].Node := This;
435+ Heap[0 ].DistSq := DistSq;
436+ // heapify downwards
437+ Heapify(0 );
438+ end ;
439+ end ;
440+ end ;
438441 end ;
439442
440443 if Delta > 0 then Test := This^.L else Test := This^.R;
0 commit comments