Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

lib/symbolset.x

Immutable ordered sets of compact Symbols.

Primary API

FunctionSummary
SymbolSet.containsReports whether symbol belongs to set.
SymbolSet.encodeReturns the bytes of a SymbolSet holding symbols in order, in a new byte Block owned by the active Scope.
SymbolSet.getindexReturns the Symbol at index, or zero when the index is out of range.
SymbolSet.indexReturns symbol’s source-order index, or -1 when it is absent.
SymbolSet.iterInitializes dest to iterate over the Symbols in source order.
SymbolSet.lenReturns the number of Symbols in set, or zero for a null set.

SymbolSet

SymbolSet.contains

int SymbolSet.contains(SymbolSet x, Symbol symbol)

Reports whether symbol belongs to set.

Source: lib/symbolset.x:112

SymbolSet.encode

Block SymbolSet.encode(Array symbols)

Returns the bytes of a SymbolSet holding symbols in order, in a new byte Block owned by the active Scope. The compiler emits them for each %<<...>> literal. Members must be distinct: the table search does not end for a repeated Symbol.

Source: lib/symbolset.x:176

SymbolSet.getindex

Symbol SymbolSet.getindex(SymbolSet x, int index)

Returns the Symbol at index, or zero when the index is out of range. Negative indices count from the end. Zero is also a valid empty Symbol, so use SymbolSet.len when an out-of-range result must be distinguished.

Source: lib/symbolset.x:119

SymbolSet.index

int SymbolSet.index(SymbolSet x, Symbol symbol)

Returns symbol’s source-order index, or -1 when it is absent. A null or empty set returns -1. The ordered table verifies the hash candidate, so a nonmember collision is not reported as membership.

Source: lib/symbolset.x:97

SymbolSet.iter

Iter SymbolSet.iter(SymbolSet x, Iter dest)

Initializes dest to iterate over the Symbols in source order. The caller owns dest, which must remain valid through every pull. The iterator borrows the generated set storage and allocates nothing. A null dest returns NULL; a null set produces an empty iterator.

Source: lib/symbolset.x:140

SymbolSet.len

size_t SymbolSet.len(SymbolSet x)

Returns the number of Symbols in set, or zero for a null set.

Source: lib/symbolset.x:91

Design notes

A SymbolSet is a compiler-generated byte string. Its perfect hash maps each member to its source-order index; the ordered Symbol table also rejects nonmembers that happen to reach the same index. The set borrows its generated static storage; no operation retains or frees it. SymbolSet.encode builds the bytes the compiler emits, so this module owns both the layout and the hash.

Tests and examples

make verify (compiler SymbolSet fixtures).