NeighborQueue

class NeighborQueue(initialSize: Int, maxHeap: Boolean)

NeighborQueue uses a LongHeap to store lists of arcs in an HNSW graph, represented as a neighbor node id with an associated score packed together as a sortable long, which is sorted primarily by score. The queue provides both fixed-size and unbounded operations via .insertWithOverflow and .add, and provides MIN and MAX heap subclasses.

Constructors

Link copied to clipboard
constructor(initialSize: Int, maxHeap: Boolean)

Functions

Link copied to clipboard
fun add(newNode: Int, newScore: Float)

Adds a new graph arc, extending the storage as needed.

Link copied to clipboard
fun clear()
Link copied to clipboard
Link copied to clipboard
fun insertWithOverflow(newNode: Int, newScore: Float): Boolean

If the heap is not full (size is less than the initialSize provided to the constructor), adds a new node-and-score element. If the heap is full, compares the score against the current top score, and replaces the top element if newScore is better than (greater than unless the heap is reversed), the current top score.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun pop(): Int

Removes the top element and returns its node id.

Link copied to clipboard
fun setVisitedCount(visitedCount: Int)
Link copied to clipboard
fun size(): Int
Link copied to clipboard
fun topNode(): Int

Returns the top element's node id.

Link copied to clipboard

Returns the top element's node score. For the min heap this is the minimum score. For the max heap this is the maximum score.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard