class

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

new(size : Int32, &)

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.

Source
new(priorities : Array(Number)) : self

Creates a new IndexPriorityQueue from the given priorities with indexes in the range [0, priorities.size).

Source

Instance methods

empty?

Returns true if the queue is empty, else false.

Source
first

Returns the index with highest priority (smallest value). Raises Enumerable::EmptyError if the list is empty.

Source
first?

Returns the index with highest priority (smallest value), or nil if the queue is empty.

Source
pop

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.

Source
priority_at(index : Int32) : Float64

Returns the priority of the element at index. Raises IndexError if index is out of bounds or inactive (removed).

Source
set_priority_at(index : Int, priority : Float64) : Nil

Updates the priority of the element at index with the given value.

NOTE: The queue is updated internally to restore the heap property.

Source
size

Returns the number of indexes in the queue.

Source
to_a

Returns the indexes as an array.

Source