HClust::IndexPriorityQueue
Inherits Reference < Object
An IndexPriorityQueue is a priority queue of contiguous zero-based
indexes.
It supports efficient access to and removal of the element with highest priority (defined as the smallest value). It is designed for optimally searching nearest neighbors (priority = dissimilarity).
It is implemented as a min binary heap (where the top is the minimum element), where the indexes and priorities are also stored separately. Note that deleted indexes are marked as inactive, but otherwise kept in memory. Therefore, indexing is not supported.
Constructors
Creates a new IndexPriorityQueue with indexes in the range [0, size), invoking the given block for each index and setting its
priority to the block's return value.
Creates a new IndexPriorityQueue from the given priorities with
indexes in the range [0, priorities.size).
Instance methods
Returns the index with highest priority (smallest value). Raises
Enumerable::EmptyError if the list is empty.
Returns the index with highest priority (smallest value), or nil
if the queue is empty.
Removes and returns the index with highest priority (smallest
value), or nil if the queue is empty.
NOTE: The queue is updated internally to restore the heap property.
Returns the priority of the element at index. Raises IndexError
if index is out of bounds or inactive (removed).
Updates the priority of the element at index with the given value.
NOTE: The queue is updated internally to restore the heap property.