std/collections
std/collections — the collections framework.
The generic Iterator / Collection / List / Set / Map
contracts the concrete classes fulfil. Each implementation lives in
its own file under std/collections/ and resolves by bare name
(use std::collections::ArrayList; etc.) regardless of file:
• ArrayList<T> → arraylist.axle (growable array)
• HashSet<T> → hashset.axle (SwissTable set)
• HashMap<K, V> → hashmap.axle (SwissTable map)
The traits below name the shared contracts; a class opts into one
with : Trait and the conformance check enforces it.Iterator and Iterable are the two protocols for (x of it) walks:
a type that declares the methods of either is iterable, whether or not
it lists the trait, and ArrayList, HashSet and HashMap declare the
methods of Iterable.
T trait Iterator<T>
One-directional cursor over a sequence of T. Drive it with thehasNext() guard before each next(); the two together walk the
elements exactly once, in order. for (x of it) writes that loop.
| Type | Method and description |
|---|---|
| hasNext(self) : bool True while at least one element remains to be returned. |
| next(self) : T Advance and return the next element. Call only after hasNext(). |
Method detail
#hasNext
True while at least one element remains to be returned.
#next
Advance and return the next element. Call only after hasNext().
T trait Iterable<T>
A collection of T that for (x of c) walks by slot, leaving the cursor
in the loop. A slot is a position in the collection's own storage; the
loop searches from where the previous slot ended, so each element is read
against the collection as it is at that moment.
| Type | Method and description |
|---|---|
| nextSlot(self, start : i64) : i64 The first live slot at or after start, or a negative number whennone remains. |
| elementAt(self, slot : i64) : T The element held in slot, a value nextSlot returned. |
Method detail
#nextSlot
The first live slot at or after start, or a negative number when
none remains.
#elementAt
The element held in slot, a value nextSlot returned.
T trait Collection<T>
The root contract every collection of T honours: membership,
cardinality, and bulk mutation. List and Set refine it with
ordering / uniqueness guarantees.
| Type | Method and description |
|---|---|
| add(self, element : T) : bool Add element; returns whether the collection changed. |
| remove(self, element : T) : bool Remove one occurrence of element; returns whether it was present. |
| clear(self) : void Drop every element, leaving the collection empty. |
| contains(self, element : T) : bool True when an equal element is held. |
| size(self) : i64 Live element count. |
| isEmpty(self) : bool True when no elements are held. |
Method detail
#add
Add element; returns whether the collection changed.
#remove
Remove one occurrence of element; returns whether it was present.
#clear
Drop every element, leaving the collection empty.
#contains
True when an equal element is held.
#size
Live element count.
#isEmpty
True when no elements are held.
T trait List<T>
An ordered, index-addressable sequence of T. Positions are dense0 .. size; ArrayList<T> is the concrete implementation.
| Type | Method and description |
|---|---|
| add(self, element : T) : bool Append element to the end; always changes the list. |
| get(self, index : i64) : T Element at index. |
| set(self, index : i64, element : T) : T Overwrite the element at index. |
| removeAt(self, index : i64) : T Remove the element at index, shifting later elements down one. |
| indexOf(self, element : T) : i64 Position of the first element equal to element. |
| contains(self, element : T) : bool True when an equal element is held. |
| size(self) : i64 Live element count. |
| isEmpty(self) : bool True when the list is empty. |
| clear(self) : void Drop every element. |
Method detail
#add
Append element to the end; always changes the list.
#get
Element at index.
IndexOutOfBoundsException when index is negative or >= size.#set
Overwrite the element at index.
IndexOutOfBoundsException when index is out of range.#removeAt
Remove the element at index, shifting later elements down one.
IndexOutOfBoundsException when index is out of range.#indexOf
Position of the first element equal to element.
-1 if absent.#contains
True when an equal element is held.
#size
Live element count.
#isEmpty
True when the list is empty.
#clear
Drop every element.
T trait Set<T>
An unordered collection of distinct T — no element appears twice.HashSet<T> is the concrete implementation.
| Type | Method and description |
|---|---|
| add(self, element : T) : bool Add element if absent; returns true only on a genuine insert. |
| remove(self, element : T) : bool Remove element; returns whether it was present. |
| contains(self, element : T) : bool True when an equal element is a member. |
| size(self) : i64 Number of distinct elements. |
| isEmpty(self) : bool True when the set is empty. |
| clear(self) : void Drop every element. |
Method detail
#add
Add element if absent; returns true only on a genuine insert.
#remove
Remove element; returns whether it was present.
#contains
True when an equal element is a member.
#size
Number of distinct elements.
#isEmpty
True when the set is empty.
#clear
Drop every element.
T trait Map<K, V>
An association of distinct keys K to values V. Lookup throws on a
miss rather than returning a sentinel, since V is non-nullable;HashMap<K, V> is the concrete implementation.
| Type | Method and description |
|---|---|
| put(self, key : K, value : V) : void Insert key, or overwrite its existing value with value. |
| get(self, key : K) : V Value bound to key. |
| remove(self, key : K) : bool Remove the entry for key; returns whether it was present. |
| containsKey(self, key : K) : bool True when key has a bound value. |
| size(self) : i64 Number of entries. |
| isEmpty(self) : bool True when the map holds no entries. |
| clear(self) : void Drop every entry. |
Method detail
#put
Insert key, or overwrite its existing value with value.
#get
Value bound to key.
NoSuchElementException when key is absent.#remove
Remove the entry for key; returns whether it was present.
#containsKey
True when key has a bound value.
#size
Number of entries.
#isEmpty
True when the map holds no entries.
#clear
Drop every entry.