class HClust::IndexPriorityQueue

Overview

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.

Defined in:

hclust/queue.cr

Constructors

Instance Method Summary

Constructor Detail

def self.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.


[View source]
def self.new(priorities : Array(Number)) : self #

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


[View source]

Instance Method Detail

def empty? : Bool #

Returns true if the queue is empty, else false.


[View source]
def first : Int32 #

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


[View source]
def first? : Int32 | Nil #

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


[View source]
def pop : Int32 | Nil #

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.


[View source]
def priority_at(index : Int32) : Float64 #

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


[View source]
def 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.


[View source]
def size : Int32 #

Returns the number of indexes in the queue.


[View source]
def to_a : Array(Int32) #

Returns the indexes as an array.


[View source]