Level F: state #
The functional model of the algorithm (docs/LEAN.md §4), a transliteration of the Python
prototype (prototype/core.py, pq.py, top_wbbt.py, wrapper.py). It is executable and is
tested against the prototype by trace replay (OrderMaintenance/Test/Replay.lean).
Conventions:
- Records live in arrays and refer to each other by index. Index 0 is a dummy and
NIL = 0, so every real index is positive (the prototype uses 0-based indices andNIL = -1). - Code runs in
EStateM Err Core. A failed guard throwsErr.guardand keeps the state reached, exactly like the prototype's exceptions; the caller then runs FALLBACK, which rebuilds everything from the element list.Err.bugmarks a situation in which the prototype would crash (an assertion, a missing key); the tests check that it never occurs. - Instrumentation of the prototype is omitted.
The zero index reserved for absent pointers and dummy array entries.
Equations
Instances For
Parameters of one core (prototype/core.py Params, plus the top structure's).
- N : Nat
Capacity parameter for the core.
- L : Nat
Logarithmic scale used in the capacity formulas.
- G : Nat
Element threshold for beginning a group split.
- T : Nat
Element threshold for beginning a chunk split.
- theta : Nat
Quiet-chunk size threshold for entering the priority queue.
- elementBits : Nat
Bit width of element labels.
- groupBits : Nat
Bit width of group labels.
- elementSpacing : Nat
Spacing used when appending an element label.
- groupSpacing : Nat
Spacing used when appending a group label.
- groupBudget : Nat
Group split steps scheduled per insertion.
- chunkBudget : Nat
Chunk split steps scheduled per insertion.
- reservationBudget : Nat
Reservation steps scheduled per insertion.
- a : Nat
Tree balance parameter controlling child capacity.
- s : Nat
Number of tree sweep steps scheduled at each visit.
- beta : Nat
Bit width of one level of a chunk’s composite tag.
- H : Nat
Maximum height of the top tree.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
An allocated element, including its order label and external handle.
- next : Nat
Next element index in the core list.
- prev : Nat
Previous element index in the core list.
- grp : Nat
Containing group index.
- lab : Nat
Order label within the containing group.
- live : Bool
Whether this element represents a live external handle.
- h : Nat
External handle represented by this element.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
A labelled run of elements and its incremental split state.
- next : Nat
Next group index in the core list.
- prev : Nat
Previous group index in the core list.
- first : Nat
First element index, or the absent-pointer sentinel.
- last : Nat
Last element index, or the absent-pointer sentinel.
- chk : Nat
Containing chunk index.
- lab : Nat
Order label within the containing chunk.
- size : Nat
Number of elements in the group.
- st : St
Current incremental split state.
- src : Nat
Source group of an overflow sibling.
- l : Nat
Left overflow sibling of a splitting group.
- r : Nat
Right overflow sibling of a splitting group.
- alive : Bool
Whether this group record is currently allocated.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
A tagged run of groups and its incremental split state.
- next : Nat
Next chunk index in the core list.
- prev : Nat
Previous chunk index in the core list.
- first : Nat
First group index, or the absent-pointer sentinel.
- last : Nat
Last group index, or the absent-pointer sentinel.
- size : Nat
Number of elements in the chunk.
- st : St
Current incremental split state.
- src : Nat
Source chunk of an overflow sibling.
- l : Nat
Left overflow sibling of a splitting chunk.
- r : Nat
Right overflow sibling of a splitting chunk.
- tag : Nat
Order tag assembled from the top-tree path.
- alive : Bool
Whether this chunk record is live rather than a tombstone.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
The side of a split receiving a table entry.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
A node of the top tree (prototype/top_wbbt.py Node). The prototype's lab dictionary
and order list are merged into table: the entries with their labels, in label order.
- height : Nat
Height above chunks, which occupy height zero.
- livePar : Nat
Parent in the live top tree.
Ordered live child indices.
- weight : Nat
Weight used by the tree balance and drain rules.
Entries and labels in increasing label order.
Tables in which this node occurs as an entry.
- first : Nat
First chunk in the node’s represented range.
- last : Nat
Last chunk in the node’s represented range.
- draining : Bool
Whether this node is undergoing a drain.
- t1 : Nat
Left target node of an active drain.
- t2 : Nat
Right target node of an active drain.
Destination side assigned to each entry during a drain.
- overflowOf : Nat
Source of this node when it is an overflow drain target.
- alive : Bool
Whether this node record is in use.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
The program counter of a top-structure job (top_wbbt.py _job, a Python generator).
Each constructor is a point where the generator is suspended.
- copy
(j : Nat)
: JobPc
Before copying level
jofx's path. - walk
(v : Option Nat)
: JobPc
At the head of the upward walk;
nonemeans "start fromlpar[y]". - afterDrain
(v up : Nat)
: JobPc
Right after
_start_drain(v)(itsyield). - fund
(v up src k : Nat)
: JobPc
Inside the sweep funding loop of
v, afterksweep steps.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Deferred construction of the top structure (init_steps, a Python generator).
- chunk : Nat
Initial chunk whose ancestor chain is being prepared.
- h : Nat
The next height to build (starts at 1;
H + 1means "finish"). - below : Nat
- tag : Nat
Composite chunk tag accumulated during preparation.
Ancestor path accumulated during preparation.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
One insert-only core with its priority queue and top structure.
- P : Params
Parameters governing this core’s capacities and scheduled work.
Element records, including a dummy record at index zero.
Group records, including a dummy record at index zero.
Chunk records, including a dummy record at index zero.
Reusable group indices outside the live group list.
- count : Nat
Number of elements inserted into this core.
- head : Nat
Head of the element list, including the dead sentinel.
- tail : Nat
Last allocated element in list order.
- firstGroup : Nat
Head of the live group list.
- firstChunk : Nat
Head of the allocated chunk list.
- ready : Bool
Whether deferred top-tree preparation is complete.
Suspended top-tree preparation, if any.
Suspended chunk reservation job, if any.
- fallbacks : Nat
Number of fallback rebuilds performed.
Head chunk index of each size bucket.
Next queued chunk within the same size bucket.
Previous queued chunk within the same size bucket.
The bucket of a chunk in the queue, 0 if absent (sizes in the queue exceed
theta ≥ 1).Next nonempty size bucket.
Previous nonempty size bucket.
- pqHi : Nat
Largest and smallest non-empty bucket, 0 if the queue is empty.
- pqLo : Nat
Smallest nonempty bucket, or zero for an empty queue.
Allocated top-tree node records.
Top-tree ancestor paths indexed by chunk.
Containing-table lists for chunk entries.
Live parents of chunks at height zero.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Stateful core computations that retain the reached state on failure.
Instances For
Arrays as total maps #
Accessors #
Raise a recoverable guard failure without discarding the current core.
Equations
Instances For
Raise an internal failure indicating an invalid program state.
Equations
Instances For
Read the parameters of the current core.
Equations
- OrderMaintenance.Model.getP = do let __do_lift ← get pure __do_lift.P
Instances For
Small list helpers #
Read the value at the first occurrence of a key in an association list.
Equations
- OrderMaintenance.Model.lookup l k = Option.map (fun (x : Nat × β) => x.snd) (List.find? (fun (x : Nat × β) => x.fst == k) l)
Instances For
Look up the label assigned to an entry in a node table.
Equations
- n.lab? e = OrderMaintenance.Model.lookup n.table e