module base.base64
Implement base64 encoding scheme
pub fn base64_encode(data: Bytes) -> str
pub fn base64_decode(text: str) -> Bytes
module base.bitset
Bit set data type.
pub fn new_bitset(n: int64) -> BitSet
Create a bit set with n bits.
pub class BitSet
Compactly store an vector of booleans
pub var m_integers: [int64]
pub var m_num_integers: int64
pub var m_width: int64
pub fn set(bit?: int64)
pub fn add(bit?: int64)
pub fn unset(bit?: int64)
pub fn remove(bit?: int64)
pub fn isset(bit?: int64) -> bool
pub fn contains(bit?: int64) -> bool
pub fn or_assign(other?: BitSet)
pub fn and_assign(other?: BitSet)
pub fn andnot_assign(other?: BitSet)
pub fn clone() -> BitSet
pub fn equals(other?: BitSet) -> bool
pub fn len() -> int64
pub fn is_empty() -> bool
pub fn first() -> int64
pub fn iter() -> BitSetIter
pub class BitSetIter
var m_bitset: BitSet
var m_slot: int64
var m_word: int64
pub fn init()
pub fn next() -> Option
var n_bits_per_int: int64
fn bit_mask(bit: int64) -> int64
fn bit_slot(bit: int64) -> int64
pub fn new_small_bitset() -> SmallBitSet
pub class SmallBitSet
A bitset with a single integer with bits.
pub var m_word: int64
pub fn set(bit?: int64)
pub fn add(bit?: int64)
pub fn unset(bit?: int64)
pub fn remove(bit?: int64)
pub fn is_empty() -> bool
pub fn clone() -> SmallBitSet
pub fn assign(other: SmallBitSet)
pub fn first() -> int64
module base.bytes
Data types for bytes
pub class Bytes
Immutable bytes
var m_bytes: [uint8]
var m_size: int64
pub fn len() -> int64
pub fn get(index: int64) -> int64
pub fn get_byte(index: int64) -> uint8
pub fn set_byte(index: int64, value: uint8)
pub fn concat(other: Bytes) -> Bytes
pub fn as_hex() -> str
Return bytes as hexadecimal text
pub fn as_array() -> [uint8]
pub fn into_reader() -> ByteReader
pub fn as_ascii() -> str
fn concat2(a: Bytes, b: Bytes) -> Bytes
pub class ByteReader
var m_bytes: Bytes
var m_index: int64
pub fn at_end() -> bool
pub fn tell() -> int64
pub fn read_bytes(size: int64) -> Bytes
pub fn peek_byte(ahead: int64) -> int64
pub fn read_byte() -> int64
pub fn read_u16_be() -> int64
pub fn read_u16_le() -> int64
pub fn read_u32_be() -> int64
pub fn read_u32_le() -> int64
pub fn read_u64_be() -> int64
pub fn read_u64_le() -> int64
pub class ByteArray
Mutable bytes
var m_bytes: [uint8]
var m_size: int64
var m_capacity: int64
pub fn append(byte?: int64)
pub fn as_array() -> [uint8]
fn grow()
pub fn clear()
pub fn get(index: int64) -> int64
pub fn set(index: int64, value: int64)
pub fn extend(bytes?: Bytes)
pub fn pack_f64_le(value?: float64)
pub fn pack_f64_be(value?: float64)
pub fn pack_f32_le(value?: float32)
pub fn pack_f32_be(value?: float32)
pub fn pack_u64_le(value?: int64)
pub fn pack_u64_be(value?: int64)
pub fn pack_u32_le(value?: int64)
pub fn pack_u32_be(value?: int64)
pub fn pack_u16_le(value?: int64)
pub fn pack_u16_be(value?: int64)
pub fn is_empty() -> bool
pub fn len() -> int64
pub fn to_bytes() -> Bytes
pub fn as_hex() -> str
pub fn byte_as_hex(byte?: uint8) -> str
pub fn bytes_from_hex_text(text: str) -> Bytes
pub fn new_bytes() -> Bytes
fn new_bytes_with_size(size: int64) -> Bytes
Bytes object with the given size. Uninitialized memory.
pub fn fill_bytes(n: int64, fill: int64) -> Bytes
pub fn bytes_from_ascii(text: str) -> Bytes
pub fn bytes_to_ascii(data: Bytes) -> str
pub fn get_byte_from_array(buffer: [uint8], index: int64) -> int64
pub fn set_byte_into_array(buffer: [uint8], index: int64, value: int64)
module base.cbor
CBOR (Concise Binary Object Representation)

See also: https://cbor.io/
pub class CborWriter
var m_buffer: ByteArray
pub fn write_int(value?: int64)
pub fn write_bool(value?: bool)
pub fn write_null()
pub fn write_undefined()
pub fn write_bytes(data?: Bytes)
pub fn write_string(text?: str)
pub fn start_array(size: int64)
pub fn start_map(size: int64)
pub fn write_float(value?: float64)
pub fn finish() -> Bytes
fn emit_varsized(major: int64, info: int64)
fn write_header(major: int64, info: int64)
fn emit_u32(value?: int64)
fn emit_u16(value?: int64)
fn emit_u8(value?: int64)
fn emit_bytes(data?: Bytes)
fn emit_byte(value?: int64)
class CborReader
var m_a: int64
fn a()
module base.crypto
pub fn md5(data: Bytes) -> Bytes
pub fn leftrotate(value: uint32, amount: int64) -> uint32
pub fn right_rotate(value: uint32, amount: int64) -> uint32
pub fn right_shift(value: uint32, amount: int64) -> uint32
pub fn compute_md5_K(K: [int64])
pub fn fill_md5_K(K: [int64])
Pre computed table of
floor(2^32 * abs(sin(i + 1)))
fn sha_pre_process(data: Bytes) -> Bytes
Append a 1 bit, and align to 512 bits.
pub fn sha1(data: Bytes) -> Bytes
pub fn sha256(data: Bytes) -> Bytes
SHA256 hash.

See also: https://en.wikipedia.org/wiki/SHA-2
module base.datetime
Date time function
pub fn unix_to_str(seconds: int64) -> str
pub fn unix_to_datetime(z: int64) -> DateTime
pub fn datetime_to_unix(dt: DateTime) -> int64
fn two_digits(n?: int64) -> str
pub fn datetime_to_str(d: DateTime) -> str
pub struct DateTime
year: int64month: int64day: int64hour: int64minute: int64second: int64
struct Civil
year: int64month: int64day: int64
fn days_from_civil(ymd: Civil) -> int64
fn civil_from_days(z: int64) -> Civil
module base.deflate
Implement RFC 1951: deflate format.

DEFLATE uses huffman trees and LZ77 compression.
pub fn deflate_decompress(data?: Bytes) -> Bytes
Decompress the given data using deflate
See: RFC 1951
fn deflate_decompress_from_reader(reader: ByteReader) -> Bytes
pub fn new_deflate_decoder(reader: ByteReader) -> DeflateDecoder
pub fn deflate_compress(data: Bytes) -> Bytes
Compress data in DEFLATE format
enum Action
Literal(int64)Copy(int64, int64)
fn find_index(base: [int64], bits: [int64], size: int64, value: int64) -> int64
struct TreeNode
freq: int64kind: TreeNodeKind
enum TreeNodeKind
Leaf(int64)Internal(TreeNode, TreeNode)
fn cmp_TreeNode(a: TreeNode, b: TreeNode) -> bool
fn get_widths(frequencies: [int64], size: int64) -> Vector[int64]
Given a set of frequencies, determine the width in bits of each symbol.
fn assign_bit_width(widths: Vector[int64], node: TreeNode, level: int64)
enum RunLengthOpcode
Literal(int64)Repeat(int64)FewZeroes(int64)ManyZeroes(int64)
class RunLengthEncoder
var m_opcodes: List[RunLengthOpcode]
pub fn encode(values: Vector[int64]) -> List[RunLengthOpcode]
Run length encoding
fn emit_run(value: int64, count: int64)
fn emit(opcode?: RunLengthOpcode)
class DeflateCompressor
var m_data: Bytes
var m_index: int64
var m_level: int64
var m_bit_writer: BitWriter
var m_hash_table: HashMap[int64,List[int64]]
pub fn compress() -> Bytes
fn write_block_header(last_block: int64, btype: int64)
fn some_compression()
fn determine_trees(actions: List[Action]) -> TreePair
fn write_dynamic_table(lengths1: Vector[int64], lengths2: Vector[int64], code_lengths: Vector[int64], opcodes: List[RunLengthOpcode])
fn run_length_encode(table: HashMap[int64,CodeEntry], opcodes: List[RunLengthOpcode])
Run length encoding
fn write_actions(pair: TreePair, actions: List[Action])
fn create_actions() -> List[Action]
fn no_compression()
fn write_uncompressed_block(size: int64, last_block: int64)
fn write_symbol(table: HashMap[int64,CodeEntry], symbol: int64)
fn write_bits(n: int64, value: int64)
pub class DeflateDecoder
var m_bit_reader: BitReader
var m_output: ByteArray
pub fn deflate() -> Bytes
fn copy_uncompressed()
fn read_dynamic_tree() -> TreePair
fn inflate_block(pair: TreePair)
fn read_bits(n?: int64) -> int64
fn read_byte() -> int64
fn read_u16_le() -> int64
fn emit_byte(b?: int64)
struct TreePair
first: Treesecond: Tree
fn create_tree(lengths: Vector[int64]) -> Tree
fn create_fixed_trees() -> TreePair
fn create_fixed_literal_lengths() -> Vector[int64]
fn create_fixed_distance_lengths() -> Vector[int64]
module base.deque
pub fn new_queue[T]() -> Queue[T]
pub fn new_queue_with_capacity[T](capacity: int64) -> Queue[T]
pub class Queue[T]
Implement a FIFO queue data type
var m_items: [T]
var m_capacity: int64
var m_length: int64
var m_head: int64
var m_tail: int64
pub fn push(value?: T)
Append a value to the queue
pub fn pop() -> T
Pop first value from the queue
pub fn clear()
pub fn len() -> int64
pub fn is_empty() -> bool
fn grow()
fn inc(value?: int64) -> int64
module base.diff
Implement diff using Myers linear space algorithm

left variables: a, n, x, left, right
right variables: b, m, y, top, bottom

Use the relation k = x - y

Implemented while reading this blog:
https://blog.jcoglan.com/2017/04/25/myers-diff-in-linear-space-implementation/
pub fn ratio(a: str, b: str) -> float64
Calculate similarity ratio between two strings.

This has remotely to do with Levenshtein distance.

Returns a value between 0 and 1 indicating similarity
pub fn diff_lines(a: Vector[str], b: Vector[str]) -> List[Edit]
Compare two lists of strings
pub fn count_diff_changes[T](edits: List[Edit]) -> int64
Count number of changes
pub fn render_diff(edits: List[Edit], show_unchanged_lines: bool)
Print diff to console
fn old_range_to_str(pos: int64, size: int64) -> str
struct UnifiedBlock
Single block of unified diff output
pos1: int64size1: int64pos2: int64size2: int64lines: List[str]has_deltas: bool
fn new_unified_block(pos1: int64, pos2: int64) -> UnifiedBlock
pub fn show_unified(edits: List[Edit], context: int64)
Create unified output, with a given amount of context
fn pos_size_to_str(pos: int64, size: int64) -> str
fn emit_block(block: UnifiedBlock)
pub fn diff_numbers(a: Vector[int64], b: Vector[int64]) -> List[Edit]
Compare two lists of integers
pub fn diff_strings(a: str, b: str) -> List[Edit]
Compare two strings
fn str_to_char_vector(s?: str) -> Vector[char]
pub fn diff_chars(a: Vector[char], b: Vector[char]) -> List[Edit]
Compare two lists of chars
pub fn diff_items[T](a: Vector[T], b: Vector[T], eq: fn (T, T) -> bool) -> List[Edit]
pub enum Edit[T]
Equal(int64, int64, Vector[T])Insert(int64, int64, Vector[T])Delete(int64, int64, Vector[T])Change(int64, int64, Vector[T], Vector[T])
struct Context[T]
Diff problem context
a: Vector[T]b: Vector[T]eq: fn (T, T) -> bool
struct Point
x: int64y: int64
class Area
pub var left: int64
pub var top: int64
pub var right: int64
pub var bottom: int64
pub fn width() -> int64
pub fn height() -> int64
pub fn to_string() -> str
fn diff_linear_space[T](ctx: Context, area: Area, edits: List[Edit])
Recursively divide and conquer the graph in subgraphs
fn find_middle_snake[T](ctx: Context, area: Area) -> Point
Simultaniously search paths from start and from end.
fn is_odd(x?: int64) -> bool
Test if the given number is odd
fn is_even(x?: int64) -> bool
Test if the given number is even
fn group_edits[T](edits: List[Edit]) -> List[Edit]
Post process edits
fn fold_edits[T](edits: List[Edit], fold_func: fn (Edit, Edit) -> Option) -> List[Edit]
Try to merge edits by using the given fold_func.
fn merge_two_edits[T](first: Edit, second: Edit) -> Option
Try to merge two edits into a single edit
fn add_change_edits[T](first: Edit, second: Edit) -> Option
module base.fs
Functionality to operate on files and folders.

TODO: merge with pathlib?
pub fn lexical_sort_paths(values?: List[Path]) -> List[Path]
pub fn path_compare(a: Path, b: Path) -> bool
pub fn new_path(filename: str) -> Path
pub fn list_to_vector[T](items?: List[T]) -> Vector[T]
pub fn vector_to_list[T](items?: Vector[T]) -> List[T]
pub class Path
var filename: str
pub fn exists() -> bool
pub fn open(mode: str) -> int64
pub fn read_text() -> str
pub fn read_lines() -> Vector[str]
pub fn write_lines(lines?: Vector[str])
Write text lines to this path
pub fn to_string() -> str
pub fn with_suffix(suffix: str) -> Path
Create a new path with the new suffix
pub fn get_stem() -> str
pub fn get_extension() -> str
pub fn read_bytes() -> Bytes
pub fn write_bytes(data: Bytes)
pub fn read_whole_file_as_bytes(path: Path) -> Bytes
pub fn write_bytes_to_file(path: Path, data: Bytes)
module base.functools
pub fn zip[L,R,P](left: List[L], right: List[R], merger: fn (L, R) -> P) -> List[P]
fn add_int(left: int64, right: int64) -> int64
pub fn sum_integers(values: List[int64]) -> int64
pub fn reduce[T](values: List[T], f: fn (T, T) -> T) -> T
pub fn map[T,V](values: List[T], function: fn (T) -> V) -> List[V]
pub fn filter[T](values: List[T], criterium: fn (T) -> bool) -> List[T]
pub fn all[T](values: List[T], check: fn (T) -> bool) -> bool
module base.graphlib
A graph consists of nodes and edges between them.
There are directed and undirected graph types.
pub class DiGraph
A directed graph
pub var nodes: Set[str]
var pred: HashMap[str,Set[str]]
var succ: HashMap[str,Set[str]]
pub fn add_node(n?: str)
pub fn add_edge(src: str, dst: str)
pub fn remove_edge(src: str, dst: str)
pub fn has_edge(src: str, dst: str) -> bool
pub fn successors(n?: str) -> Set[str]
pub fn has_preds(n?: str) -> bool
pub fn has_edges() -> bool
pub fn topological_sort(g?: DiGraph) -> Option
pub class Graph
Undirected graph
pub var m_nodes: Set[str]
var m_neighbours: HashMap[str,Set[str]]
pub fn add_node(n?: str)
pub fn add_edge(src?: str, dst?: str)
pub fn has_edge(src?: str, dst?: str) -> bool
pub fn neighbours(n?: str) -> Set[str]
pub fn find_max_cliques(g: Graph) -> List[Set[str]]
Find maximum cliques with the Bron Kerbosch algorithm
fn bron_kerbosch(r: Set[str], p: Set[str], x: Set[str], g: Graph, output: List[Set[str]])
An algorithm for solving the clique problem:
https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm
pub fn find_all_cliques_of_size(g: Graph, k: int64) -> List[Set[str]]
fn bron_kerbosch_k(r: Set[str], p: Set[str], x: Set[str], g: Graph, k: int64, output: List[Set[str]])
A mutated Bron Kerbosch algorithm
pub fn dfs(g: DiGraph, start: str) -> List[str]
Depth first search
pub class LengauerTarjanAlgorithm
Lengauer Tarjan algorithm
var a: int64
fn do()
module base.gzip
See RFC-1952: GZIP file format.
fn read_zero_terminated_string(reader: ByteReader) -> str
pub fn gzip_decompress(data?: Bytes) -> Bytes
pub fn gzip_compress(data: Bytes) -> Bytes
pub fn calc_crc32(data: Bytes) -> int64
pub fn zlib_decompress(data: Bytes) -> Bytes
pub fn zlib_compress(data: Bytes) -> Bytes
pub fn calc_adler32(data: Bytes) -> int64
module base.hashlib
pub fn elf_hash(text: str) -> uint32
pub fn djb2(text: str) -> uint32
module base.hashmap
Hash map data type.

Idea: have an array with buckets.
pub fn new_hashmap_int[V]() -> HashMap[int64,V]
Create a new hashmap with integer keys
pub fn new_hashmap_uint32[V]() -> HashMap[uint32,V]
Create a new hashmap with uin32 keys
pub fn new_hashmap_str[V]() -> HashMap[str,V]
Create a new hashmap with string keys
pub fn new_hashmap_char[V]() -> HashMap[char,V]
Create a new hashmap with char keys
pub fn new_hashmap[K,V](f_hash: fn (K) -> uint32, f_eq: fn (K, K) -> bool) -> HashMap[K,V]
pub fn str_hash(text?: str) -> uint32
pub fn str_eq(a?: str, b?: str) -> bool
pub fn int_eq(a: int64, b: int64) -> bool
pub fn int_hash(x: int64) -> uint32
pub fn uint32_eq(a: uint32, b: uint32) -> bool
pub fn uint32_hash(x: uint32) -> uint32
pub fn char_eq(a: char, b: char) -> bool
pub fn char_hash(x: char) -> uint32
pub class HashMap[K,V]
pub var num_buckets: int64
var m_threshold: int64
var m_size: int64
pub var m_buckets: [Option]
pub var f: HashableApi
pub fn init()
pub fn maybe_get(key: K) -> Option
fn get_hash(key: K) -> uint32
fn get_index(hash: uint32) -> int64
pub fn contains(key: K) -> bool
pub fn get(key: K) -> V
pub fn get_or_else(key: K, default: V) -> V
pub fn insert(key: K, value: V)
pub fn remove(key: K)
pub fn drop(key: K)
pub fn pop(key: K) -> Option
remove an item from this dictionary
fn debug_display()
pub fn len() -> int64
pub fn clear()
pub fn is_empty() -> bool
fn rehash()
fn create_buckets(n: int64)
pub fn values() -> List[V]
pub fn iter() -> HashMapIter[K,V]
pub class HashMapIter[K,V]
var index: int64
var m_pair_ptr: Option
var m: HashMap[K,V]
pub fn next() -> Option
struct HashableApi[T]
f_hash: fn (T) -> uint32f_eq: fn (T, T) -> bool
struct KeyValuePair[K,V]
key: Khash: uint32value: Vnext: Option
module base.heapq
Binary heap implementation.

A binary heap is an implementation for a priority queue.
pub fn new_int_min_queue() -> PriorityQueue[int64]
fn cmp_int_item(a?: int64, b?: int64) -> bool
pub fn new_priority_queue_with_capacity[T](capacity: int64, f: fn (T, T) -> bool) -> PriorityQueue[T]
struct Hack[T]
f: fn (T, T) -> bool
pub class PriorityQueue[T]
var m_items: [T]
var m_size: int64
var m_capacity: int64
var hack: Hack
pub fn push(item?: T)
pub fn pop() -> T
fn sift_down(index?: int64)
fn sift_up(index?: int64)
pub fn is_empty() -> bool
pub fn len() -> int64
fn get(index?: int64) -> T
fn compare(index1?: int64, index2?: int64) -> bool
fn swap(a?: int64, b?: int64)
module base.huffman
Procedures related to Huffman coding.
pub fn decode_symbol(tree: Tree, bit_reader: BitReader) -> int64
Decode a value with the given Huffman tree
pub fn create_table(tree: Tree) -> HashMap[int64,CodeEntry]
pub struct CodeEntry
code: int64length: int64
pub fn encode_symbol(table: HashMap[int64,CodeEntry], symbol: int64, bit_writer: BitWriter)
pub class BitReader
pub var m_bitbuf: int64
pub var m_bitcnt: int64
pub var m_reader: ByteReader
pub var m_reverse: bool
pub fn read_bits(n?: int64) -> int64
pub class BitWriter
pub var m_output: ByteArray
var m_bitbuf: int64
var m_bitcnt: int64
pub fn write_bits(n: int64, value: int64)
pub fn flush()
pub fn to_bytes() -> Bytes
pub struct Tree
counts: [int64]symbols: [int64]
pub fn zero_int_array(size: int64) -> [int64]
module base.integersetlib
Implementation of range-set
pub class IntegerSet
pub var ranges: List[Range]
pub fn to_string() -> str
pub fn equals(other?: IntegerSet) -> bool
pub fn is_empty() -> bool
pub fn contains(value: int64) -> bool
pub fn difference(other?: IntegerSet) -> IntegerSet
pub fn union(other?: IntegerSet) -> IntegerSet
pub fn first() -> int64
pub fn new_empty_int_set() -> IntegerSet
Create an new empty integer set
pub fn new_int_set(begin: int64, end: int64) -> IntegerSet
Create a new integer set with a single range
pub fn integer_set_from_ranges(ranges: List[Range]) -> IntegerSet
fn range_equals(a: Range, b: Range) -> bool
pub fn integer_set_equals(a: IntegerSet, b: IntegerSet) -> bool
fn is_true(b?: bool) -> bool
fn integer_set_intersection(self: IntegerSet, other: IntegerSet) -> IntegerSet
pub fn integer_set_difference(self: IntegerSet, other: IntegerSet) -> IntegerSet
module base.json
JSON data serialization library
pub enum JsonValue
Integer(int64)String(str)Bool(bool)Object(Vector[KeyValue])Array(Vector[JsonValue])Null
struct KeyValue
key: strvalue: JsonValue
pub fn write_json_to_file(filename: Path, obj: JsonValue)
pub fn read_json_from_file(filename: Path) -> JsonValue except JsonException
pub fn parse_json(text: str) -> JsonValue except JsonException
pub fn json_to_string(value?: JsonValue) -> str
pub struct JsonException
message: strpos: int64
pub class JsonBrowser
var m_value: JsonValue
var m_stack: Vector[JsonValue]
pub fn push_value(value: JsonValue)
pub fn pop_value()
pub fn get_attribute(attr: str) -> JsonValue
pub fn has_attribute(attr: str) -> bool
pub fn find_attribute(attr: str) -> Option
pub fn get_array_values() -> Vector[JsonValue]
pub fn get_array_attribute(attr: str) -> Vector[JsonValue]
pub fn get_text_attribute(attr: str) -> str
pub fn get_integer_attribute(attr: str) -> int64
pub fn get_boolean_attribute(attr: str) -> bool
pub fn is_string() -> bool
pub fn get_text() -> str
Get text from current node
pub fn get_integer() -> int64
Get integer from current node
pub fn get_boolean() -> bool
Get boolean from current node
pub fn enter_attribute(attr: str)
pub class JsonBuilder
var m_object_stack: List[JsonObjectBuilder]
var m_array_stack: List[JsonArrayBuilder]
pub fn begin_object()
pub fn add_attribute(attr: str, value: JsonValue)
pub fn add_boolean_attribute(attr: str, value: bool)
pub fn add_text_attribute(attr: str, text: str)
pub fn add_text_as_element(text: str)
pub fn add_integer_attribute(attr: str, value: int64)
pub fn end_object() -> JsonValue
pub fn end_object_as_element()
pub fn end_object_as_attribute(attr: str)
pub fn begin_array()
pub fn add_element(value: JsonValue)
pub fn end_array() -> JsonValue
pub fn end_array_as_attribute(attr: str)
class JsonObjectBuilder
var m_attributes: Vector[KeyValue]
pub fn add_attribute(attr: str, value: JsonValue)
pub fn finish() -> JsonValue
class JsonArrayBuilder
var m_values: Vector[JsonValue]
pub fn add_element(value: JsonValue)
pub fn finish() -> JsonValue
class Parser
var m_buffer: List[JsonToken]
var lexer: Lexer
pub fn parse_value() -> JsonValue except JsonException
fn parse_object() -> JsonValue except JsonException
fn parse_array() -> JsonValue except JsonException
fn parse_string() -> str except JsonException
fn parse_colon() except JsonException
fn get_token() -> JsonToken
fn unget_token(token: JsonToken)
fn unexpected(token: JsonToken, expected: str) -> JsonException
struct JsonToken
kind: JsonTokenKindpos: int64
enum JsonTokenKind
BracketLeftBracketRightBraceLeftBraceRightCommaColonInteger(int64)String(str)Id(str)EofUnexpectedEofError(char)
fn token_to_str(token: JsonToken) -> str
class Lexer
var text: str
var index: int64
var n: int64
pub fn init()
pub fn lex() -> JsonToken
fn create_token(kind?: JsonTokenKind) -> JsonToken
fn is_id(c: char) -> bool
module base.leb128
LEB128 encoding.
pub fn pack_unsigned_leb128(out: ByteArray, value: int64)
pub fn pack_signed_leb128(out: ByteArray, value: int64)
module base.listtype
List data type
pub fn list1[T](v1?: T) -> List[T]
pub fn list2[T](v1?: T, v2?: T) -> List[T]
pub fn list3[T](v1?: T, v2?: T, v3?: T) -> List[T]
pub fn list4[T](v1?: T, v2?: T, v3?: T, v4?: T) -> List[T]
pub fn list5[T](v1?: T, v2?: T, v3?: T, v4?: T, v5?: T) -> List[T]
pub fn list6[T](v1?: T, v2?: T, v3?: T, v4?: T, v5?: T, v6?: T) -> List[T]
pub fn list7[T](v1?: T, v2?: T, v3?: T, v4?: T, v5?: T, v6?: T, v7?: T) -> List[T]
pub fn list8[T](v1?: T, v2?: T, v3?: T, v4?: T, v5?: T, v6?: T, v7?: T, v8?: T) -> List[T]
pub fn list9[T](v1?: T, v2?: T, v3?: T, v4?: T, v5?: T, v6?: T, v7?: T, v8?: T, v9?: T) -> List[T]
pub class List[T]
var head_element: Option
var tail_element: Option
var length: int64
pub fn append(val?: T)
pub fn prepend(val?: T)
pub fn is_empty() -> bool
pub fn len() -> int64
pub fn clear()
pub fn drop_front()
pub fn pop_front() -> T
pub fn iter() -> ListIter[T]
pub fn first() -> T
pub fn drop_last()
pub fn pop_last() -> T
pub fn last() -> T
pub fn get(index: int64) -> T
pub fn set(index: int64, value: T)
fn get_element(index: int64) -> ListElement
pub fn delete_at(index: int64)
pub fn reversed() -> List[T]
pub fn take(n: int64) -> List[T]
Create a new list with the first n items
pub fn take_extend(other?: List[T])
pub fn extend2(other?: List[T])
struct ListElement[T]
next: Optiondata: T
pub class ListIter[T]
pub var next_element: Option
pub fn next() -> Option
module base.logging
Logger.
var log_level: int64
pub fn set_log_level(level: int64)
pub fn log_error(message?: str)
pub fn log_warning(message?: str)
pub fn log_info(message?: str)
pub fn log_debug(message?: str)
pub fn log_trace(message?: str)
fn log_it(level: str, message: str)
module base.math
pub var pi: float64
pub var e: float64
pub fn min(a: int64, b: int64) -> int64
pub fn max(a?: int64, b?: int64) -> int64
pub fn fmin(a?: float64, b?: float64) -> float64
pub fn fmax(a?: float64, b?: float64) -> float64
pub fn abs(a?: int64) -> int64
pub fn fabs(a?: float64) -> float64
pub fn sqrt(x?: float64) -> float64
Take the square root
pub fn factorial(x?: int64) -> int64
pub fn sin(x?: float64) -> float64
pub fn cos(value?: float64) -> float64
fn sin_kernel(x?: float64) -> float64
Implement sin on range -pi/4 .. pi/4 by using a taylor series

x^3 x^5 x^7
sin(x) ~ x - --- + --- - --- + --- ....
3! 5! 7!
pub fn tan(value?: float64) -> float64
pub fn degrees(radians: float64) -> float64
Convert radians to degrees
pub fn radians(degrees: float64) -> float64
Convert degrees to radians
pub fn round_up_to_multiple(value: int64, multiple: int64) -> int64
Integer round to higher multiple
fn fmod(x?: float64, divisor: float64) -> float64
pub fn hypot(x?: float64, y: float64) -> float64
pub fn modulo(value: int64, divisor: int64) -> int64
pub fn powf(x?: float64, y?: float64) -> float64
Raise x to the power of y.

Implemented as:
x^y = e^(y*log(x))

This follow from: x^y = exp(log(x))^y = exp(y * log(x))
pub fn log10(x?: float64) -> float64
pub fn log2(x?: float64) -> float64
pub fn log(x?: float64) -> float64
Natural logarithm

See: https://en.wikipedia.org/wiki/Natural_logarithm
For implementation algorithm: https://ben.land/post/2021/02/24/power-without-math-lib/

Use the series:
2 ?
log(x) = Sum ----- * (---)^(2n+1)
2*n+1 ?
pub fn exp(x?: float64) -> float64
Use Taylor series:

x^1 x^2 x^3
e^x = 1 + --- + --- + --- + ...
1! 2! 3!
pub fn floor(value?: float64) -> int64
pub fn ceil(value?: float64) -> int64
module base.optiontype
pub enum Option[D]
Some(D)None
pub fn option_unwrap[T](option?: Option) -> T
pub fn option_unwrap_or[T](option: Option, default: T) -> T
pub fn option_is_some[T](opt?: Option) -> bool
pub fn option_is_none[T](opt?: Option) -> bool
module base.pathlib
pub fn basename(path: str) -> str
retrieve 'bla' from 'for/bar/bla.txt'
pub fn split_path(path: str) -> List[str]
module base.profiling
Application profiling
enum Event
Enter(str)Leave
struct TimedEvent
time: int64event: Event
pub class Profiler
var m_events: List[TimedEvent]
pub fn enter(name: str)
Enter a measured zone
pub fn leave()
pub fn add_event(event?: Event)
pub fn write_json(filename: Path)
Generate speedscope compatible json file
fn get_frame_index(name: str, frames: List[SpeedscopeFrame]) -> int64
struct SpeedscopeEvent
typ: strat: int64frame: int64
struct SpeedscopeFrame
name: strfile: strline: int64col: int64
fn write_speedscope_json(filename: Path, events: List[SpeedscopeEvent], frames: List[SpeedscopeFrame])
module base.random
pub fn new_rand() -> Rand
pub class Rand
32 bit PCG random number generator

Really minimal PCG32 code, ported to slang lang.
Original C code by (c) 2014 M.E. O'Neill / pcg-random.org
Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
pub var state: uint64
pub var inc: uint64
pub fn seed(initstate: uint64, initseq: uint64)
pub fn next() -> uint32
Generate a random 32 bit number
range: 0 <= x < 2**32
pub fn next_float() -> float64
Generate a random float with 32 bits of randomness
range: 0 <= x < 1

Note that '1' is not included in the possible range.
pub fn next_int(min: int64, max: int64) -> int64
Generate a random interger

range:
min <= x < max
or
min <= x <= (max - 1)

Note that 'max' is not included in the possible range.
module base.rangelib
pub struct Range
begin: int64end: int64
pub fn ranges_overlap(self: Range, other: Range) -> bool
pub fn range_contains(self: Range, value: int64) -> bool
pub fn range_to_string(r?: Range) -> str
module base.regex
Regex library

Based on [Brzozowski derivatives](https://en.wikipedia.org/wiki/Brzozowski_derivative).

Ported from code: [MichaelPaddon/epsilon](https://github.com/MichaelPaddon/epsilon)
pub fn find(pattern: str, text: str) -> Option
pub fn find_all(pattern: str, text: str) -> List[Match]
Find all regular expression in the given text.
pub fn find_all_text(pattern: str, text: str) -> List[str]
fn get_text(m: Match) -> str
pub fn split_at_pattern(text: str, pattern: str) -> List[str]
Split a string at the given regex
fn machine_find_all(machine: Machine, text: str) -> List[Match]
pub struct Match
begin: int64end: int64text: str
pub fn compile(pattern: str) -> Machine
fn create_machine(rx: Regex) -> Machine
fn contains_regex(lst: List[Regex], rx: Regex) -> int64
class Machine
pub var start_state: int64
pub var error_state: int64
pub var states: List[State]
pub fn next_state(state_nr: int64, c: char) -> int64
pub fn accepts(state_nr: int64) -> bool
struct State
transitions: List[Transition]accepts: bool
struct Transition
range: Rangeto_state: int64
fn parse(pattern: str) -> Regex
pub fn print_machine(machine: Machine)
fn print_regex(rx: Regex, level: int64)
class Parser
var index: int64
var n_size: int64
var text: str
pub fn parse() -> Regex except ParseError
Parse a regular expression.
fn parse_term() -> Regex except ParseError
fn parse_factor() -> Regex except ParseError
fn parse_range() -> Regex except ParseError
Parse [0-9:a-z] or [^abc]
fn peek() -> char
fn eat() -> char except ParseError
fn error(message: str) -> ParseError
struct ParseError
position: int64message: str
fn new_char_set(c: char) -> IntegerSet
Single character set
fn sigma() -> IntegerSet
Return full ascii set
fn symbol_regex(c: char) -> Regex
Regex for single character
fn symbol_set_regex(s: IntegerSet) -> Regex
fn epsilon_regex() -> Regex
fn null_regex() -> Regex
pub fn sigma_regex() -> Regex
Regex with all symbols!
enum PartKind
Kleene(Regex)Symbol(IntegerSet)Concat(Regex, Regex)LogicalAnd(Regex, Regex)LogicalOr(Regex, Regex)LogicalNot(Regex)NullEpsilon
fn kleene_regex(r: Regex) -> Regex
fn concat_regex(left: Regex, right: Regex) -> Regex
fn logical_and_regex(left: Regex, right: Regex) -> Regex
fn logical_or_regex(left: Regex, right: Regex) -> Regex
fn logical_not_regex(r: Regex) -> Regex
class Regex
pub var kind: PartKind
pub fn to_string() -> str
pub fn equals(other: Regex) -> bool
pub fn kleene() -> Regex
pub fn concat(other: Regex) -> Regex
pub fn logical_and(other: Regex) -> Regex
pub fn logical_or(other: Regex) -> Regex
pub fn is_null() -> bool
pub fn is_epsilon() -> bool
pub fn is_kleene() -> bool
pub fn is_logical_not() -> bool
pub fn derivative(c: int64) -> Regex
pub fn derivative_classes() -> List[IntegerSet]
pub fn is_nullable() -> bool
pub fn nu() -> Regex
fn product_intersections(a?: List[IntegerSet], b?: List[IntegerSet]) -> List[IntegerSet]
module base.rope
Rope data type for modifiable text.

Idea is to store text in a binary tree. Each node has
extra meta-data. Leaf nodes contain the actual characters of
the text.

A rope data type can be used in a text editor. Inserting text
can be seen as splitting the tree, and then merging the nodes
again.
pub fn new_rope(text: str) -> RopeText
pub class RopeText
var m_root: Node
pub fn get_text() -> str
pub fn insert(pos: int64, text: str)
Insert text at the given position
pub fn delete(pos: int64, size: int64)
Delete some text
fn new_leaf_node(text: str) -> Node
fn merge_nodes(left: Node, right: Node) -> Node
fn split_node(node: Node, pos: int64) -> NodePair
fn to_text(node: Node) -> str
enum NodeType
Leaf(str)NonLeaf(Node, Node)
struct Node
size: int64ty: NodeType
struct NodePair
left: Noderight: Node
module base.settype
Set datatype, build upon the HashMap datatype.
pub fn new_set[T](f_hash: fn (T) -> uint32, f_eq: fn (T, T) -> bool) -> Set[T]
pub fn new_str_set() -> Set[str]
pub fn new_int_set() -> Set[int64]
pub fn new_uint32_set() -> Set[uint32]
pub class Set[T]
var m_items: HashMap[T,bool]
pub fn add(value?: T)
pub fn contains(value?: T) -> bool
pub fn remove(value?: T)
pub fn clear()
pub fn len() -> int64
pub fn is_empty() -> bool
pub fn iter() -> SetIter[T]
pub fn first() -> T
fn new_empty_set() -> Set[T]
pub fn union(other?: Set[T]) -> Set[T]
New set with items from both sets
pub fn union_add(other?: Set[T])
Add all items from the other set
pub fn intersection(other?: Set[T]) -> Set[T]
New set with only items that are in both sets
pub fn difference(other?: Set[T]) -> Set[T]
New set with only items from other removed
pub fn equals(other?: Set[T]) -> bool
pub class SetIter[T]
var m_it: HashMapIter[T,bool]
pub fn next() -> Option
module base.shapelib
Geometry function library.
pub struct Point
x: int64y: int64
pub fn str_point(p?: Point) -> str
pub struct Path
points: List[Point]
pub struct Polygon
path: Path
pub fn shoelace(points: List[Point]) -> float64
module base.sorting
pub fn find_min_value[T](values: List[T], cmp: fn (T, T) -> bool) -> T
pub fn find_max_value[T](values: List[T], cmp: fn (T, T) -> bool) -> T
pub fn sort_list[T](x?: List[T], cmp: fn (T, T) -> bool) -> List[T]
fn merge_sort[T](m: List[T], cmp: fn (T, T) -> bool) -> List[T]
fn merge_two[T](left: List[T], right: List[T], cmp: fn (T, T) -> bool) -> List[T]
module base.strlib
pub fn split_string2(text: str, sep: str) -> List[str]
Split string by other string
pub fn split_string(text: str, sep: char) -> List[str]
pub fn rsplit_string(text: str, sep: char, maxsplit: int64) -> List[str]
Split string based on separator, and a maximum amount of splits
pub fn lexical_sort(values?: List[str]) -> List[str]
pub fn string_compare(a: str, b: str) -> bool
pub fn str_repeat(text: str, count: int64) -> str
pub fn str_pad_right(text: str, length: int64, fill: str) -> str
pub fn str_pad_left(text: str, length: int64, fill: str) -> str
pub fn str_join(parts: List[str], sep: str) -> str
pub fn is_space(c: char) -> bool
pub fn is_tab(c: char) -> bool
pub fn is_lf(c: char) -> bool
fn is_cr(c: char) -> bool
fn is_whitespace(c?: char) -> bool
pub fn str_to_int(text?: str) -> int64
pub fn hex_to_int(hextext: str) -> int64
Convert hex text
pub fn bin_to_int(bintext: str) -> int64
Convert bin text to integer value
For example, convert 101 to 5
pub fn is_digit(c: char) -> bool
Check if a character is a digit.
pub fn digit_to_int(c: char) -> int64
pub fn hex_digit_to_int(c: char) -> int64
pub fn is_hex_digit(c: char) -> bool
Check if a character is a hex digit.
pub fn int_to_hex_string(value?: int64) -> str
pub fn hex_char(value?: int64) -> char
pub fn is_bin_digit(c: char) -> bool
pub fn bin_digit_to_int(c: char) -> int64
pub fn trim(text?: str) -> str
pub fn find_char(text: str, criterium: fn (char) -> bool) -> Option
pub fn reverse_find_char(text: str, criterium: fn (char) -> bool) -> Option
fn str_comparison(a: str, b: str) -> int64
pub fn split_lines(text: str) -> List[str]
pub class StringBuilder
var m_parts: List[str]
var m_size: int64
pub fn len() -> int64
pub fn push(v?: str)
pub fn get() -> str
module base.terminal
Terminal colors
pub enum Color
BlackRedGreenYellowBlueMagentaCyanWhite
pub fn colored_text(text: str, color: Color) -> str
fn sgr(code?: int64) -> str
fn get_color_code(color: Color) -> int64
module base.text_out
pub fn new_text_out(filename: Option) -> TextOut
pub fn new_console_text_out() -> TextOut
enum TextOutType
ConsoleFile(int64)
pub class TextOut
var m_out: TextOutType
var indentation: int64
pub fn indent()
pub fn dedent()
pub fn emit(text?: str)
pub fn end()
module base.unittest
Unit testing helper functions.
pub fn assert_str_equals(a?: str, b?: str)
pub fn assert_int_equals(a?: int64, b?: int64)
pub fn assert_almost_equals(a?: float64, b?: float64)
pub fn assert_list_equals(a?: List[str], b?: List[str])
pub fn assert_bytes_equals(a?: Bytes, b?: Bytes)
pub fn assert_true(condition?: bool)
pub fn assert_false(condition?: bool)
module base.utils
pub fn panic(message?: str) -> UNREACHABLE-TYPE
pub fn unimplemented(message?: str) -> UNREACHABLE-TYPE
pub fn assert(condition: bool, message: str)
module base.vectype
Vector datatype.
As opposed to the Linked List, we use an array here.
The allocated array will be larger than the actual amount of values,
and when appendingwe might need to re-allocate the array and copy
the old values.
pub fn new_vector[T]() -> Vector[T]
pub fn new_vector_with_capacity[T](capacity: int64) -> Vector[T]
pub fn new_vector_of_size[T](size: int64, default: T) -> Vector[T]
pub fn vec1[T](v1?: T) -> Vector[T]
pub fn vec2[T](v1?: T, v2?: T) -> Vector[T]
pub fn vec3[T](v1?: T, v2?: T, v3?: T) -> Vector[T]
pub fn vec4[T](v1?: T, v2?: T, v3?: T, v4?: T) -> Vector[T]
pub fn vec5[T](v1?: T, v2?: T, v3?: T, v4?: T, v5?: T) -> Vector[T]
pub fn vec8[T](v1?: T, v2?: T, v3?: T, v4?: T, v5?: T, v6?: T, v7?: T, v8?: T) -> Vector[T]
pub class Vector[T]
var m_size: int64
var m_capacity: int64
var m_elements: [T]
pub fn is_empty() -> bool
pub fn append(value?: T)
pub fn pop_last() -> T
pub fn drop_last()
pub fn drop_last_n(n: int64)
pub fn extend(other?: Vector[T])
Append all elements of other to this vector
pub fn clear()
fn grow()
pub fn len() -> int64
pub fn get(index: int64) -> T
pub fn set(index: int64, value: T)
pub fn first() -> T
pub fn last() -> T
pub fn slice(offset: int64, amount: int64) -> Vector[T]
Extract a sub sequence
pub fn take(amount?: int64) -> Vector[T]
Create a new vector with the given amount of items
pub fn skip(amount?: int64) -> Vector[T]
pub fn concat(other: Vector[T]) -> Vector[T]
module base.xml
XML parsing routines.
pub class Node
pub var tag: str
pub var m_attributes: List[Attribute]
pub var m_child_nodes: List[Node]
pub var m_content: str
pub fn add_attribute(name: str, value: str)
pub fn add_child(node?: Node)
pub fn add_content(text: str)
struct Attribute
name: strvalue: str
pub fn emit_xml(node: Node, filename: Option)
class XmlWriter
var out: TextOut
pub fn write_header()
pub fn write_node(node: Node)
fn attributes_to_string(attributes: List[Attribute]) -> str
fn attribute_to_string(attribute: Attribute) -> str
fn indent()
fn dedent()
fn emit(text?: str)
pub fn read_xml() -> Node
module base.zip
ZIP file format.
pub fn open_archive(filename: Path) -> ZipArchive
pub class ZipArchive
var m_x: int64
module std