class HClust::IndexList
- HClust::IndexList
- Reference
- Object
Overview
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.
Defined in:
hclust/index_list.crConstructors
-
.new(size : Int32)
Creates a new
IndexList
with indexes in the range[0, size)
.
Instance Method Summary
-
#delete(index : Int32) : Nil
Removes the given index from the list if present.
-
#each(& : Int32 -> ) : Nil
Yields each index in the list.
-
#each(*, within range : Range(Int32 | Nil, Int32 | Nil), skip : Int32 = 0, & : Int32 -> ) : Nil
Yields each index in the list within the given range.
-
#each(*, omit index : Int32, & : Int32 -> ) : Nil
Yields each index except index.
-
#first : Int32
Returns the first index.
-
#first? : Int32 | Nil
Returns the first index or
nil
if the list is empty. -
#includes?(index : Int32) : Bool
Returns
true
if the list includes the given index, elsefalse
. -
#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.
-
#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.
-
#nearest_to(index : Int32, dism : DistanceMatrix) : Tuple(Int32, Float64)
Returns the nearest index to the given index based on the distance matrix.
-
#size : Int32
Returns the total number of indexes in the list.
-
#to_a : Array(Int32)
Returns an
Array
with all the indexes in the list. -
#unsafe_succ(index) : Int32
Returns the succeeding index to
index
, without doing any bounds check.
Constructor Detail
Instance Method Detail
Yields each index in the list within the given range. It discards skip elements before yielding.
Yields each index except index. Useful for iterating in pairs.
Returns true
if the list includes the given index, else false
.
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.
Returns the nearest index to the given index based on the block's returns value.
Returns the nearest index to the given index based on the distance matrix.
Returns the succeeding index to index
, without doing any bounds
check.