class

HClust::IndexList

Inherits Reference < Object

An IndexList is an ordered collection of contiguous zero-based indexes.

It supports efficient iteration and removal so it performs better than an Array when there are frequent deletions.

Internally, it is implemented as a double-linked list such that deleted indexes are marked as inactive, but otherwise kept in memory. Therefore, indexing is not supported. Traversal is performed using the #each methods.

The most typical use case of a IndexList is for representing a list of nodes, where finding the closest pair is often desired. Hence, convenience methods for finding the nearest index based on a given distance metric are provided.

Constructors

new(size : Int32)

Creates a new IndexList with indexes in the range [0, size).

Source

Instance methods

delete(index : Int32) : Nil

Removes the given index from the list if present.

Source
each

Yields each index in the list.

Source
each(*, within range : Range(Int32 | Nil, Int32 | Nil), skip : Int32 = 0, & : Int32 -> ) : Nil

Yields each index in the list within the given range. It discards skip elements before yielding.

Source
each(*, omit index : Int32, & : Int32 -> ) : Nil

Yields each index except index. Useful for iterating in pairs.

Source
first

Returns the first index. Raises Enumerable::EmptyError if the list is empty.

Source
first?

Returns the first index or nil if the list is empty.

Source
includes?(index : Int32) : Bool

Returns true if the list includes the given index, else false.

Source
nearest_to(index : Int32, dism : DistanceMatrix, & : Int32, Float64 -> Float64) : Tuple(Int32, Float64)

Returns the nearest index to the given index based on the block's returns value. Both the index and distance taken from the distance matrix are yielded such that the block may compute a new distance if needed.

Source
nearest_to(index : Int32, & : Int32 -> T) : Tuple(Int32, T) forall T

Returns the nearest index to the given index based on the block's returns value.

Source
nearest_to(index : Int32, dism : DistanceMatrix) : Tuple(Int32, Float64)

Returns the nearest index to the given index based on the distance matrix.

Source
size

Returns the total number of indexes in the list.

Source
to_a

Returns an Array with all the indexes in the list.

Source
unsafe_succ(index) : Int32

Returns the succeeding index to index, without doing any bounds check.

Source