Count the amount of elements in the collection.
⚠️ In most cases, this should be an O(1)
operation. However, there are
cases where this can be an O(n)
operation. Therefore, it is recommended
to always cache the result in a local variable.
Returns an object which is able to sift through the values in this collection.
The order by which the elements are traversed depends on the kind of collection. For unordered collections, the iteration order is unspecified and may even differ between two iterations on the same collection.
Remove all elements from this collection, effectively setting the collection to the empty collection.
Copies all elements in the collection to a new one of the same kind.
Converts the entire collection to a range.
Generated using TypeDoc
A data structure that maps elements to different memory locations so that they can be very efficiently stored and retrieved.
Choosing the key and determining how to detect duplicates
In the next example, we index the states of a [finite-state machine][1]. Each state has a unique
id
that we'd like to use as key. There is only one instance of each uniqueFSMState
, so we can instructHashIndex
to use the much simpler strict equality check instead of the more advanced isEqual. Likewise, keys are just numbers, so we can save come CPU cycles by directly comparing them.AVLTreeIndex for when the elements have to be sorted and there are frequent lookups
RBTreeIndex for when the elements have to be sorted and there are frequent mutations