Class: BoundedHeap<T>
Defined in: heap.ts:45 Fixed-capacity max-heap that keeps the N smallest items bydistance.
Designed for top-K nearest-neighbour use: insert M candidates, retrieve
the N closest in O(M log N) total time and O(N) memory regardless of
how many candidates are scanned.
Internally a max-heap on distance, so the largest distance among the
kept N sits at the root. New entries are accepted only when they are
strictly closer than the current worst.
Example
Type Parameters
T
T extends Distanced
Element type; must expose a numeric distance field.
Constructors
Constructor
new BoundedHeap<Defined in: heap.ts:56T>(limit):BoundedHeap<T>
Parameters
limit
number
Maximum number of items to retain. Once full, new
inserts are accepted only when their distance is strictly less
than the current worst-kept element’s distance.
Returns
BoundedHeap<T>
Properties
limit
Defined in: heap.ts:49 Maximum number of elements the heap will retain.readonlylimit:number
Accessors
size
Get Signature
get size(): number
Defined in: heap.ts:95
Current number of retained elements (≤ limit).
Returns
number
Methods
insert()
insert(Defined in: heap.ts:67 Insert a candidate. If the heap is below capacity, the entry is added unconditionally. Otherwise the entry replaces the current worst-kept element if and only ifentry):void
entry.distance < currentWorst.distance.
Time complexity: O(log limit).
Parameters
entry
T
Returns
void
peek()
peek():Defined in: heap.ts:82T|undefined
Returns
T | undefined
The element with the largest retained distance, or
undefined if the heap is empty. This is the entry that would be
evicted next on a closer insert.
toSorted()
toSorted(): T[]
Defined in: heap.ts:90
Returns
T[]
A new array of the retained entries sorted ascending by
distance (nearest first). Does not mutate the heap.