The Rete network#
Engine#
Scope#
The C Rete network implements exactly the pattern forms, expression operators and action verbs the DS lowering emits, and nothing else.
It is libds’s only rule-evaluation substrate, and nothing selects it. No textual rule language is parsed at runtime: the network topology and every expression tree arrive in binary form. The network spawns no thread and runs no background work.
Feature mechanisms#
Each DS feature the compiler emits maps to one network mechanism.
DS feature |
Mechanism |
|---|---|
schema and slot types |
schema descriptors; value arrays of the kinds in Value storage |
|
alpha node, all slots bound |
|
alpha test |
|
alpha regex test |
|
join test over bound variables |
|
NOT node |
|
join test over the monotonic sample minus the fact’s |
|
multi-pattern join chain with a join test on |
|
NOT sub-node excluding older anchors |
refraction |
per-terminal refraction table keyed by token identity |
|
RHS assert action |
|
RHS assert action and truth-maintenance registration |
pure |
folded at compile time; no network mechanism |
sync-impure |
bind-once in the RHS expression context |
async |
request and response rules; no network primitive |
cooldown |
the terminal’s |
|
RHS expression nodes dispatched to builtins |
series aggregation in |
join test calling a series builtin |
|
schema with no slots; its assert and retract drive time-bound tests |
string interpolation |
one |
|
|
logical facts |
truth maintenance: reference count and dependency table |
TTL expiry |
deadline in the fact; swept once per pump, before anything fires |
no-op reassertion |
slot equality check, with per-slot tolerance, at assert |
|
schema with |
|
schema with |
(Spec: [IRET.2.1])
Wiring#
ds_engine_new creates the Rete engine (ds_rete_engine_create, held as engine->rete_engine), registers the builtins (ds_register_builtins) and fills the engine’s ds_rete_adapter_config_t with the action-verb callbacks (ds_engine_wire_rete_adapters).
libds drives the network through these entry points:
Operation |
Entry point |
|---|---|
create, destroy |
|
load the compiled network |
|
before-fire and after-fire hooks |
|
assert, retract |
|
run the agenda |
|
register a builtin |
|
(Spec: [IRET.15.1])
Engine create and destroy#
ds_rete_engine_create initialises the string-intern table, the schema registry, the agenda (an empty binary heap), the truth-maintenance dependency table, the builtin table, the clock and the fire hooks, in that order.
The fire hooks start NULL. ds_rete_engine_destroy tears down in reverse order and frees in-flight tokens and activations, the interned strings with the intern table, schema descriptors, node graphs and expression trees. When initialisation fails part-way, every subsystem already initialised is freed and no engine is returned.
(Spec: [IRET.18.1], Source: runtime/src/libds/rete/agenda.h)
Clock#
Clock functions#
The Rete engine’s clocks are two caller-supplied functions sharing one context pointer: clock_fn returns the monotonic reading and wall_fn the UTC wall reading, or no value.
ds_rete_set_clock, which takes the monotonic function and the context, and ds_rete_set_wall_clock, which takes the wall function, install them; each returns ds_result_t and refuses a NULL function with DS_ERR_INVAL. Their defaults read clock_gettime(CLOCK_MONOTONIC) and clock_gettime(CLOCK_REALTIME); a DS engine installs functions returning its held samples. The engine calls them only at the sample points, and no other code reads the time. A NOW node reads the held wall sample, and a monotonic_ns() node the held monotonic sample, as direct field reads; the now and monotonic_ns builtins read the same samples. The clock source is the architecture.
(Spec: [IRET.14], [IRET.14.1], [IRET.14.2], [IRET.14.3], [IRET.18.1])
Compiled network#
Network atoms#
The compiled network is one AlphaNode, BetaNode or TerminalNode atom per node, with no container message.
Atom |
Carries |
|---|---|
|
|
|
|
|
|
Nodes reference each other by node_id, a uint32, never by array position. Schema descriptors are not in these atoms: the schema atom family registers them into the Rete schema registry first. An expression tree is a protobuf message with a top-level oneof over expression kinds and embedded child messages. A CallExpr carries a numeric BuiltinFn op, which the loader stores on the CALL node; no name is interned.
(Spec: [IRET.16], proto: alfa.proto, beta.proto, term.proto, rete_expr.proto)
Load#
The artefact loader, dsc/rete_loader.c, decodes the network atoms, and ds_rete_load_network builds the in-memory node graph from them.
Decode each atom body with
protobuf-c; a decode failure isDS_ERR_DSC_DECODE, before any other check of the body. A node withnode_id0, or with anode_idanother node holds, isDS_ERR_RETP_INVALID.Check that every
node_idreference resolves before any pointer is built; the first that does not isDS_ERR_RETP_INDEX_OOB.The schemas are already registered.
Build the alpha nodes, compile each regex test’s pattern and wire each node into its schema’s alpha-dispatch entry.
Build the beta nodes: join-test expression trees, the negative flag, and the left-parent and right-alpha links.
Build the terminal nodes and their RHS expression trees.
Wire the downstream links: beta children, terminal children, and beta inputs on alpha nodes.
A failing step returns its error and spends the engine, and the loader undoes nothing it applied (Failed load). An engine loads one artefact for its life. For a program compiled with logical: false, the truth-maintenance table is not initialised: no table entries, withdraw scratch or overflow buffers are allocated.
(Spec: [IRET.15.2], [IRET.16.8], [IRET.18.2], [IRET.18.2.1], [IRET.21], [IRET.23.6], [RDSC.11.1], [RDSC.11.4])
Values#
Value storage#
A slot value is a tagged union: a kind discriminant and one payload.
Kind |
Payload |
Storage |
|---|---|---|
|
64-bit signed |
inline |
|
double |
inline |
|
boolean |
inline |
|
UTC nanoseconds and a zone offset |
inline |
|
none |
inline |
|
pointer and length |
interned, not owned by the value |
|
the target’s fact ID |
inline |
|
UTF-8 document tree |
heap-allocated and owned, or borrowed from the working-memory wrapper that owns it |
|
none |
inline |
|
numerator and denominator |
inline |
A fact slot carries one of the slot-value kinds; Unbound (a let slot not yet bound), Ratio (the exact ratio currency conversion yields and rounding consumes) and a borrowed Json are evaluator-only. The set is closed. Copying a String or Bytes value copies no bytes, and neither is NUL-terminated: a reader uses the length. A FactRef holds an ID, so a target that leaves working memory leaves no dangling pointer. An owned Json value belongs to the fact owning the slot, which frees it before the fact. A fact’s slot values are a flat array of ds_rete_val_t sized from its schema.
(Spec: [IRET.1.3], [IRET.1.5], [IRET.3.1], [IRET.3.3], [IRET.20.3])
String intern table#
The per-engine string table holds the pinned and counted entries of String interning in one pointer space.
Operation |
Effect |
|---|---|
|
non-mutating lookup, for the no-op check |
|
find or insert, and increment; once per |
|
decrement, and free and remove at zero; once per slot at fact retract |
|
insert saturated |
The table is open-addressed with tombstone deletion. A value equal to a pinned literal shares the literal’s pointer and stays pinned. A release that would take a count below zero trips an assertion. At the first pump the engine pins "" and $ClockTick and freezes the pinned set: a later pinned insert of a new string trips an assertion, and counted inserts stay legal.
(Spec: [IRET.1.4], [IRET.1.4c], [IRET.3.2], Source: runtime/src/libds/rete/intern.h, runtime/src/libds/engine.c)
Computed strings#
A string the engine computes and does not store in a fact slot is never interned.
An interpolated string, a gensym, a Json-to-string conversion, a cache read’s value and a where operand live in a per-engine fire-scoped arena of chained slabs, reset at pump entry. Each copy takes its own span, and growth chains a new slab, so a live pointer never moves. A computed string emitted into a fact slot is interned counted at the emit’s commit, before the reset.
Slot equality at assert#
The no-op check compares an incoming fact with the existing fact of the same schema and identity key, slot by slot.
Slot |
Comparison |
|---|---|
no tolerance |
value equality; |
tolerance |
exactly equal, or |
|
structural deep equality |
When every slot compares equal, the assertion is suppressed. Fact equality is Fact identity.
(Spec: [IRET.3.4], [RLOW.3.7.4], [LFAC.2.5.1], [LUNI.7.4])
Alpha network#
Alpha node#
An alpha node is one pattern’s participation in the network for one schema.
It holds the schema it matches, its alpha tests, its alpha memory and its downstream beta inputs. Two rules with identical patterns and tests on one schema share one alpha node, deduplicated by the compiler: one ds_rete_alpha_node_t may be the right input of several beta nodes.
(Spec: [IRET.6.1], [IRET.6.6], Source: runtime/src/libds/rete/alpha.h)
Alpha dispatch#
Each schema has a compact integer ID, and alpha dispatch is a flat array indexed by it.
Each entry lists the alpha nodes registered for that schema. Dispatching an asserted or retracted fact is one index and an iteration over that schema’s alpha nodes. The schema IDs and the per-schema arrays are Schema registry.
(Spec: [IRET.1.7])
Alpha tests#
On fact assert, the engine evaluates the alpha tests of every alpha node registered for the fact’s schema.
Tests short-circuit: the first test answering false skips the fact for that node. A fact passing every test is inserted into the alpha memory, and the node’s beta inputs are notified. Two tests can fault instead of answering: one whose slot_index names no slot of the schema, and a regex test whose subject is not a String. The engine does not short-circuit on either: the fact is rejected if another test of the node answers false, and the fault is raised only if none does.
A regex test’s pattern is compiled once, at load, and stored in the alpha node; matching calls RE2 through ds_re2_match.
Alpha memory#
The alpha memory is a hash set keyed by fact ID.
Insert and remove are O(1) on average, and the set iterates for a join against a new right fact.
(Spec: [IRET.6.5])
Beta network#
Token#
A token is one partial match: the facts bound so far, one per LHS pattern position, in pattern order.
Field |
Holds |
|---|---|
|
the number of bound pattern positions |
|
the bound facts, indexed by pattern position |
|
the completion stamp the agenda orders by |
|
the cached hash of the fact-ID tuple |
|
the intrusive link into a beta memory |
A token at a node with n patterns holds n facts: facts[n-1] is the newest, and the rest carry forward from the left parent. A binding is read directly, as token->facts[i]->slots[j]. The hash is an XOR-rotation over the fact IDs, a pre-filter for duplicate detection and refraction lookup and not a key: a collision is resolved by tokens_equal for duplicates and by the fact-ID tuple for refraction. Adding a token to a beta memory allocates nothing.
Beta node#
A beta node joins tokens arriving on its left with facts arriving on its right, and passes the matches to its children.
Its left parent is another beta node, or none, which makes working memory the left source. Its right input is an alpha node. It holds its join tests and a negative flag. Only the left side is stored, as the left memory of tokens; the right side is the alpha node’s memory. Beta children and terminal children are kept in separate lists, and a node may feed both.
(Spec: [IRET.7.4], Source: runtime/src/libds/rete/beta.h)
Join tests#
A join test is a predicate over the token and the candidate right fact.
Join tests implement where predicates and the within and then … within constraints. They are evaluated in any order and combine as an absorbing and: a false rejects the pair whatever another test raises, and that fault reaches no surface. When no test answers false and several fault, the pair yields the one fault the absorbing and selects. A pair passes only if every test answers true.
Equality anchor under linear_scan false#
In a program compiled with linear_scan: false, every beta node of a positive pattern has an equality join test BINOP(EQ, VAR(left, i, j), VAR(right, k)), unless both schemas have empty keys, and the loader extracts it as the node’s anchor.
The loader stores (i, j, k) in the node’s lmem_idx_* and ralpha_idx_* fields and compiles a typed comparator over t->facts[i]->slots[j] and f->slots[k] that bypasses the expression evaluator. The comparator probes the index; the remaining join tests run as usual. A test is a legal anchor only when it is decided: both slots non-nullable and the comparison unable to raise by their declared types. The loader never anchors on a test that could answer null or raise.
(Spec: [IRET.7.5.1])
Join algorithm#
Each beta node handles four events.
Event |
Action |
|---|---|
right activation (a fact added to the alpha memory) |
for each left token, build the extended token and evaluate the join tests; propagate each pass to every child |
left activation (a token from the left parent) |
for each fact in the right alpha memory, build the extended token and evaluate the join tests; propagate each pass |
right retraction (a fact removed from the alpha memory) |
send a retraction downstream for each left token whose fact at that pattern position is the retracted fact; no join test is evaluated |
left retraction (a token removed from the left parent) |
send a retraction downstream for each extended token built from it |
A token retraction propagates depth-first to the terminals. At a terminal, it removes the activation from the agenda if it has not fired, and ends the activation, withdrawing the justifications its firing recorded.
NOT node#
A NOT node is a beta node with the negative flag: a token passes only when the join finds no right fact.
Event |
Action |
|---|---|
left activation |
count the right facts that join; at zero, propagate the token unchanged; otherwise record the blockers |
right activation |
for each left token the new fact joins, record it as a blocker; a token that had none retracts its downstream token |
right retraction |
for each token the fact blocks, remove the blocker, with no join test evaluated; a token left with none propagates downstream |
A token’s block count is the number of right facts its left-token join index records against it, keyed by token identity; the index is a flat hash map, and there is no separate count structure. A passing token carries only its left facts: fact_count is unchanged downstream.
Sequence chains#
A then … within sequence compiles to a linear, left-associative chain of join nodes.
alpha(A) → beta_join_1 → alpha(B) → beta_join_2(test: ts_B - ts_A < T) → terminal
Each further then C within T2 appends one join node, whose within is a join test on the preceding pair. A latest anchor adds a NOT node after the sequence’s last join. It blocks the match when a fact f of the anchor’s schema has ts_a < f.ts < ts_b and ts_b − f.ts < T, and none of the anchor’s and the followers’ wheres answers false with f in the anchor’s place. Only the first follower’s window and ordering involve f.
(Spec: [IRET.7.10])
Terminals#
Terminal node#
A terminal node turns a fully matched token into an activation.
It holds the rule’s interned name, its terminal ordinal and its RHS action list. On a token it creates an activation and inserts it into the agenda; on the token’s retraction it removes it. The terminal ordinal is the rule’s zero-based index in the artefact’s terminal sequence, read directly by the comparator. A terminal holds the refraction table and the edge-once set of Refraction.
(Spec: [IRET.8], [IRET.8.1], [IRET.8.2], Source: runtime/src/libds/rete/terminal.h)
Justifications#
A firing records its activation as a justification for each fact its logical emits assert, and for no other.
An explicit emit records none. When a supporting token is retracted, terminal_left_retract copies the truth-maintenance IDs to a stack array, withdraws them from the truth-maintenance table and retracts each fact, which may cascade. Under logical: false it only removes the terminal token from the token pool.
Expressions#
Expression nodes#
An expression is a tree of tagged C structs, evaluated by a recursive walk over an evaluation context.
Each node is of one kind:
Kind |
Node |
|---|---|
literal |
an |
var |
a slot reference by pattern position and slot index |
binop |
binary arithmetic, comparison, logical or bitwise |
unop |
unary |
call |
a builtin invocation: an op and its arguments |
interp |
an interpolated string: literal text, values under their specs and time fields |
now |
a clock-source read |
json-path |
traversal of a |
if |
a conditional |
bind, bind-ref |
a |
coalesce |
|
is-test |
|
entry-stamp |
the entry stamp of the fact bound at a pattern position |
Name resolution happens at lowering: a var names a position, and evaluation performs no lookup. A pure let folds at lowering; a sync-impure one leaves a bind and bind-ref pair.
Evaluation context#
An evaluation reads only its context.
Field |
Holds |
|---|---|
|
the current partial match |
|
the candidate right fact, during a join test |
|
the |
|
the number bound |
|
builtin dispatch and the clock |
right_fact is absent when a RHS action is evaluated. A var whose pattern_index is below token->fact_count reads token->facts[i]->slots[j]; DS_RETE_VAR_RIGHT_FACT reads ctx->right_fact->slots[j]. The bind frame is stack-allocated and zeroed at RHS entry: a bind evaluates its expression and stores it at bind_frame[bind_index], and a bind-ref reads it back.
Evaluation order#
and and or evaluate their operands in any order and stop once the result is decided, with the absorbing result.
A faulting operand (a trap, a TypeError or an EngineError) does not end the evaluation. The evaluator holds the fault and evaluates the rest. A false (true for or) among the rest decides the result and discards every held fault. When nothing decides, the expression yields the one fault the absorbing order selects. A discarded or unselected fault reaches no surface.
(Spec: [IRET.9.5])
Ill-typed operations#
Arithmetic on wrong types, and a format spec its value cannot render, yield no value and raise.
Condition |
Fault |
|---|---|
an operand is |
|
no operand is |
|
otherwise |
|
The null test comes first. Json provenance starts at every read of a Json slot, is transitive and rule-local, flows through a let, and clears at a :: cast and at ??. The compiler computes it and lowers it onto the node as Expr.json_tainted; the evaluator reads it. An absent flag is clean. An interpolation segment carries the flag like any node. An absorbed fault of either kind abandons nothing and halts nothing. An unresolved Json path, and a path resolving to JSON null, read as null and raise nothing.
(Spec: [IRET.9.6], proto: rete_expr.proto)
Operator table#
Each DS operator is one binop or unop kind.
DS |
Node |
|---|---|
|
BINOP, ARITH |
|
BINOP, INT_ARITH |
|
BINOP, CMP |
|
BINOP, LOGICAL |
|
BINOP, BITWISE |
|
UNOP, BIT_NOT |
|
UNOP, LOGICAL_NOT |
|
UNOP, NEGATE |
In a program compiled with linear_scan: false, the pump path never reaches a DS_RETE_EXPR_JSON_PATH node, or a DS_RETE_EXPR_INTERP node producing a novel string.
Working memory operations#
Assert#
ds_rete_wm_assert checks the fact’s identity key, then inserts the fact and propagates it.
Find an existing fact of the schema whose KEY slots match exactly. With no KEY slot, any fact of the schema matches; with every slot KEY, only an identical tuple does.
If one is found and its MUTABLE slots compare equal under slot equality at assert, suppress the assertion and return the existing fact.
If one is found and a MUTABLE slot differs, retract it, then continue.
Allocate a fact with a fresh monotonic ID and set
assert_nsto the held monotonic sample.Under
ttlscope, setdeadline_ns = assert_ns + default_ttl_ns.Under
logicalscope, setjustif_count = 0.For each alpha node of the schema, evaluate its tests; on a pass, insert the fact into the alpha memory and activate each downstream beta input.
Emit
DS_EV_FACT_ASSERT.
The fact’s fields are Rete fact.
(Spec: [IRET.19.1])
Retract#
ds_rete_wm_retract removes a fact from the network.
Remove the fact from each alpha memory holding it, and right-retract each downstream beta input.
Token retractions propagate depth-first to the terminals, which remove their pending activations.
A
logicalfact’sjustif_countis kept by the truth-maintenance path. A plain retract of alogicalfact removes it unconditionally.Emit
DS_EV_FACT_RETRACT.Free the fact.
(Spec: [IRET.19.2])
TTL sweep and tick#
The TTL expiry sweep iterates every live fact with deadline_ns > 0 and calls ds_rete_wm_retract on each with now_ns >= deadline_ns.
A retraction cascades and may enqueue activations that fire on the fact’s absence. The engine never ticks between two firings of one pump, and ds_rete_run does not tick.
The clock tick is a fact of the slotless synthetic schema $ClockTick. libds asserts it into the network’s own fact store, not the working-memory table: it is not counted, not delivered to the fact callbacks, and not on the stream as a fact event. A then … within test compares two facts’ ts values and is not re-evaluated by the tick.
A token that joins the tick is formed again on every tick, with the new tick’s fact. While its time-dependent test stays true those tokens are one match: the edge-once set holds its refraction, keyed by the matched fact, and its justifications carry over. A test that goes false ends the match, and one that goes true again makes a new one.
(Spec: [IRET.19.3], [IRET.19.4], [IRET.19.5], [IRET.11.3.5], [IRET.12.2])
Memory#
Ownership#
The network follows libds’s single-ownership discipline.
Object |
Owner |
Lifetime |
|---|---|---|
|
the caller of |
until |
|
the engine |
the engine’s |
alpha, beta and terminal node graphs |
the engine |
from load until destroy |
|
the engine |
from load until destroy; read-only after the load |
interned strings |
the intern table |
|
|
working memory |
from |
|
the beta node’s left memory |
from the join until retraction frees it |
|
the agenda |
from the terminal’s activation until its match ends |
A retracted token’s downstream extended tokens are freed first, depth-first and post-order. Expression nodes are allocated individually at load. A builtin receiving a Json argument borrows it.
Open-addressing map#
oa#
oa is the open-addressing hash map behind the network’s and working memory’s hash tables.
Two tables are not oa tables: the intern table, whose pinned and counted entries share one pointer space and delete by tombstone, and each terminal’s refraction table, which a generation stamp empties in O(1). A probe array of u32 slots indexes dense, packed key and value arrays. Each dense entry has a cached 32-bit hash, and a reverse map from dense index to slot. Capacity is zero or a power of two, at most 2³¹, and the live count stays strictly below it. Each table is configured with its key size, value size, growth threshold (default 70 %), hash, equality and value-destructor callbacks, a callback context, and a lock flag that forbids growth.
(Spec: [IRET.28], [IRET.28.1], [IRET.28.3], [IRET.28.3.1], Source: runtime/src/libds/oa.h)
oa tables#
The engine’s oa tables, by the number code comments cite.
# |
Table (field, file) |
Key |
Hash and equality |
Value |
|---|---|---|---|---|
1 |
|
|
pointer |
|
3 |
|
|
the slots’ content |
|
4 |
|
|
integer |
|
5 |
|
|
integer |
|
6 |
|
|
|
|
7 |
|
|
as #6 |
|
8 |
|
|
pointer |
|
10 |
|
|
|
|
11 |
|
|
integer |
|
12 |
|
|
integer |
|
13 |
|
|
|
|
14 |
|
|
|
|
15 |
|
|
|
none |
16 |
|
|
|
|
17 |
|
|
the zone key |
|
Tables #1, #4 and #12 are iterated with ds_oa_val_at, #4 and #12 under oa determinism; #12 is iterated on the join scan. Tables #5 to #8 are the multimaps of oa_list. #10 keeps its doubly linked left_head list beside it, for ordered traversal. #13’s discard path finds an activation by act->token and checks that the stored value is that activation; the activation’s doubly linked list stays beside it. A clone and a replay build further oa tables that live only for that operation.
(Spec: [IRET.28.2], [IRET.28.13])
oa invariant#
After every public operation, an oa table satisfies seven invariants.
Invariant |
|
|---|---|
RI-1 |
|
RI-2 |
|
RI-3 |
each slot is empty (0) or holds a dense index plus one, in |
RI-4 |
|
RI-5 |
every entry is reachable by probing from its home slot without crossing an empty slot |
RI-6 |
no two entries have equal keys |
RI-7 |
each |
ds_oa_check, compiled under DS_DEBUG, asserts all seven and that cap is 0 or a power of two with len < cap. The engine composes it with its own invariants: ridx and ltok are mutual inverses, lmem_map has left_count entries, and every act_map value is a live activation on the activation list.
(Spec: [IRET.28.4], [IRET.28.15])
oa hashing#
A key’s slot is its mixed hash masked by cap - 1.
The callback returns a u64, and the table applies oa_mix64 to it. The callback is a pure function of the logical key; for a handle key it may depend on pointer values, which move only the probe location. The stored dhash skips most equality calls and rehashes on growth without calling the hash.
(Spec: [IRET.28.5])
oa operations#
oa operations are amortised O(1); iteration is O(len).
Operation |
Behaviour |
|---|---|
|
records the parameters, allocates nothing, cannot fail; |
|
sets |
|
returns a pointer into the table’s value storage, or |
|
finds or appends the key; a new value is zeroed; grows first when needed |
|
removes by backward shift and swaps the last dense entry into the hole; never fails, never shrinks |
|
runs the value destructor on every value and keeps the capacity and arrays |
|
clears, then frees the arrays |
Lookup is linear probing from the mixed hash: an empty slot ends the search, and equality runs only on a matching cached hash. Growth doubles cap, or sets the initial capacity, moves the dense arrays by memcpy and re-seats the slots from the cached hashes, with no hash, equality or destructor call. A backward-shift delete clears the freed slot before scanning, and updates each moved entry’s dslot. A pointer from ds_oa_get is valid until the next put, del, reserve, clear or free on the table. Iteration walks the dense arrays by index; deleting while iterating runs from high index to low. Values are relocatable by memcpy.
On failure, a table stays a valid map: ds_oa_put and ds_oa_reserve return DS_ERR_OOM with the table unchanged.
(Spec: [IRET.28.6], [IRET.28.6.1], [IRET.28.6.2], [IRET.28.6.3], [IRET.28.6.4], [IRET.28.6.5], [IRET.28.6.6], [IRET.28.12], [IRET.28.14.1])
oa value lifecycle#
The value destructor runs when an entry leaves the table, and never on growth.
It runs on ds_oa_del, before the swap overwrites the entry, on ds_oa_clear and on ds_oa_free. Growth and ds_oa_reserve move values by memcpy. A plain pointer, u32 or POD value has no destructor.
(Spec: [IRET.28.7])
oa_list#
oa_list is the value of the multimap tables (ridx, lmem_idx, ralpha_idx, ltok_idx): a key’s set of element pointers.
It holds OA_LIST_INLINE (8) pointers inline, equal to DS_RIDX_INLINE, and overflows to an owned heap array. Element order within a list is not stable. ds_oa_list_free is every multimap table’s value destructor.
(Spec: [IRET.28.8], [IRET.28.14.3])
oa determinism#
An oa table’s iteration order is its dense-vector order: append on insert, last into the hole on delete.
It is a function of the operation sequence alone, independent of capacity, pointer values and platform. The mixed hash and the mask move only probe locations. No timetag is derived from the order in which these tables are traversed.
(Spec: [IRET.28.10], [IRET.28.10.1], [IRET.28.10.3])
oa memory#
An oa table of capacity cap occupies 4·cap bytes of slots and (ksize + vsize + 8)·cap bytes of dense arrays.
The 8 bytes are the cached hash and the reverse slot index.
(Spec: [IRET.28.14.2])