std.collections
Indexable interface
pub interface Indexable<T>
fn get(index: int): T
mut fn set(index: int, value: T): void
stdlib/std/collections.lyr:22
List class
pub class List<T> :: [Indexable<T>, Iterable<T>]
data: (?T)[]
count: int
pub fn length(): int
pub fn iter(): Iterator<T>
pub fn isEmpty(): bool
pub fn capacity(): int
pub mut fn push(value: T): void
pub mut fn pop(): ?T
pub fn get(index: int): T
pub mut fn set(index: int, value: T): void
pub mut fn clear(): void
pub fn toArray(): T[]
stdlib/std/collections.lyr:40
emptyList function
pub fn emptyList<T>(): List<T>
stdlib/std/collections.lyr:163
ListIterator class
pub class ListIterator<T> :: [Iterator<T>]
source: List<T>
index: int
pub mut fn next(): ?T
stdlib/std/collections.lyr:170
collect function
pub fn collect<T>(source: Iterator<T>): List<T>
Collects an iterator into a List<T>.
Here rather than in std.iter, because the dependency runs this way: std.collections imports
std.iter, not the reverse. std.iter.collectArray is the variant without that dependency,
and it is quadratic because a T[] copies on every append. This one doubles and is linear.
stdlib/std/collections.lyr:189
Map class
pub class Map<K :: [Hashable<K>, Equatable<K>], V>
keys: (?K)[]
values: (?V)[]
states: int[]
count: int
used: int
pub fn length(): int
pub fn isEmpty(): bool
pub fn containsKey(key: K): bool
pub fn get(key: K): ?V
pub mut fn set(key: K, value: V): void
pub mut fn remove(key: K): ?V
stdlib/std/collections.lyr:212
emptyMap function
pub fn emptyMap<K :: [Hashable<K>, Equatable<K>], V>(): Map<K, V>
stdlib/std/collections.lyr:354
sortList function
pub fn sortList<T :: [Ordered<T>]>(xs: List<T>): void
Sorts in place by the natural order of the type.
stdlib/std/collections.lyr:384
sortListBy function
pub fn sortListBy<T>(xs: List<T>, less: fn(T, T) -> bool): void
Sorts in place with a comparison of your own.
less(a, b) must return true when a comes STRICTLY before b. A less returning true
for equal elements destroys stability; a contradictory less makes the output arbitrary but
crashes nothing, because the algorithm only compares.
stdlib/std/collections.lyr:393
Set class
pub class Set<T :: [Hashable<T>, Equatable<T>]>
items: (?T)[]
states: int[]
count: int
used: int
pub fn length(): int
pub fn isEmpty(): bool
pub fn contains(value: T): bool
pub mut fn add(value: T): bool
Adds and returns true when the value was NEW.
The return value saves a preceding contains, which would probe twice.
pub mut fn remove(value: T): bool
Removes and returns true when the value was present.
pub fn iter(): Iterator<T>
stdlib/std/collections.lyr:476
SetIterator class
pub class SetIterator<T :: [Hashable<T>, Equatable<T>]> :: [Iterator<T>]
source: Set<T>
index: int
pub mut fn next(): ?T
stdlib/std/collections.lyr:599
emptySet function
pub fn emptySet<T :: [Hashable<T>, Equatable<T>]>(): Set<T>
stdlib/std/collections.lyr:615
union function
pub fn union<T :: [Hashable<T>, Equatable<T>]>(a: Set<T>, b: Set<T>): Set<T>
stdlib/std/collections.lyr:622
intersect function
pub fn intersect<T :: [Hashable<T>, Equatable<T>]>(a: Set<T>, b: Set<T>): Set<T>
stdlib/std/collections.lyr:629
difference function
pub fn difference<T :: [Hashable<T>, Equatable<T>]>(a: Set<T>, b: Set<T>): Set<T>
stdlib/std/collections.lyr:640
isSubset function
pub fn isSubset<T :: [Hashable<T>, Equatable<T>]>(a: Set<T>, b: Set<T>): bool
stdlib/std/collections.lyr:648
MapKeyIterator class
pub class MapKeyIterator<K :: [Hashable<K>, Equatable<K>], V> :: [Iterator<K>]
source: Map<K, V>
index: int
pub mut fn next(): ?K
stdlib/std/collections.lyr:666
MapValueIterator class
pub class MapValueIterator<K :: [Hashable<K>, Equatable<K>], V> :: [Iterator<V>]
source: Map<K, V>
index: int
pub mut fn next(): ?V
stdlib/std/collections.lyr:682
keys function
pub fn keys<K :: [Hashable<K>, Equatable<K>], V>(m: Map<K, V>): Iterator<K>
stdlib/std/collections.lyr:698
values function
pub fn values<K :: [Hashable<K>, Equatable<K>], V>(m: Map<K, V>): Iterator<V>
stdlib/std/collections.lyr:702
listContains function
pub fn listContains<T :: [Equatable<T>]>(xs: List<T>, value: T): bool
stdlib/std/collections.lyr:712
listIndexOf function
pub fn listIndexOf<T :: [Equatable<T>]>(xs: List<T>, value: T): ?int
The position of the first occurrence, or null when there is none.
stdlib/std/collections.lyr:724