collections

Generated by tinox doc

tinox.core.collections, bundled with the compiler and also available as a standalone tinox-central package.

Stack and queue

import tinox.core.collections
class Main
{
    fnc main() -> Int32
    {
        const stack: Stack<Int64> = Stack::new()
        stack.push(1)
        stack.push(2)
        stack.push(3)
        println("stack pop: " + stack.pop().toString()) // 3 (LIFO)

        const queue: Queue<Int64> = Queue::new()
        queue.enqueue(1)
        queue.enqueue(2)
        queue.enqueue(3)
        println("queue dequeue: " + queue.dequeue().toString()) // 1 (FIFO)

        const pair: Pair<String, Int64> = Pair::new("age", 30)
        println(pair.getFirst() + " = " + pair.getSecond().toString())
        return 0
    }
}

class Collections

Methods

fn newStack() → Stack<T>
fn newQueue() → Queue<T>
fn newPair(first: T, second: U) → Pair<T, U>

@Errorclass EmptyCollectionError

* Thrown by `Stack.pop/peek` and `Queue.dequeue/peek` on an empty collection.

Fields

messageString

@Errorclass IndexError

* Thrown by `Lists::get` when the index is outside the list.

Fields

messageString

@Errorclass KeyError

* Thrown by `Maps::getOrThrow` when the key is not present.

Fields

messageString

class Lists<T>

* Checked list access: `list[i]` aborts on a bad index, `Lists::get` throws a typed * `IndexError` the caller can catch or declare.

Methods

@Throwsfn get(list: List<T>, index: Int64) → T

class Maps<V>

* Checked map access: strict `map.get` aborts on a missing key, `Maps::getOrThrow` * throws a typed `KeyError` the caller can catch or declare.

Methods

@Throwsfn getOrThrow(map: Map<String, V>, key: String) → V

class Pair<T, U>

* A pair of two values of potentially different types.

Fields

firstT
secondU

Methods

fn new(first: T, second: U) → Pair<T, U>
fn getFirst() → T
fn getSecond() → U

class Queue<T>

* A First-In-First-Out (FIFO) queue of elements of type T.

Fields

dataList<T>

Methods

fn new() → Queue<T>
fn enqueue(value: T) → Nothing
@Throwsfn dequeue() → T
@Throwsfn peek() → T
fn isEmpty() → Bool
fn size() → Int64

class Stack<T>

* A Last-In-First-Out (LIFO) stack of elements of type T.

Fields

dataList<T>

Methods

fn new() → Stack<T>
fn push(value: T) → Nothing
@Throwsfn pop() → T
@Throwsfn peek() → T
fn isEmpty() → Bool
fn size() → Int64