lib/symbolset.x
Immutable ordered sets of compact Symbols.
Primary API
| Function | Summary |
|---|---|
SymbolSet.contains | Reports whether symbol belongs to set. |
SymbolSet.getindex | Returns the Symbol at index, or zero when the index is out of range. |
SymbolSet.index | Returns symbol’s source-order index, or -1 when it is absent. |
SymbolSet.iter | Initializes dest to iterate over the Symbols in source order. |
SymbolSet.len | Returns 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:100
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:107
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:83
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:128
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:77
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.
Tests and examples
make verify (compiler SymbolSet fixtures).