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.
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.
| 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 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) : i32 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 : i32) : T Element at index. |
| set(self, index : i32, element : T) : T Overwrite the element at index. |
| removeAt(self, index : i32) : T Remove the element at index, shifting later elements down one. |
| indexOf(self, element : T) : i32 Position of the first element equal to element. |
| contains(self, element : T) : bool True when an equal element is held. |
| size(self) : i32 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) : i32 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) : i32 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.