pub enum CollectOp {
WeightedNew,
RandRoll,
HeapPush,
HeapPop,
HeapPeek,
}Expand description
The collections+ operation selected by an Opcode::Collect
instruction’s kind byte (NS-A7, docs/stdlib-spec.md §8, issue #1113).
Weighted[T] construction plus rand::roll, and the humble heap —
verbs over ordinary arrays, min-heap, ordering per the ruled §4b
doctrine (total_order_cmp, the one comparison core). RandRoll is
the only draw (one RNG-cell write); everything else is placement or
pure reads.
Variants§
WeightedNew
[pairs] → Weighted[T] — pops ONE array of flattened
weight, value, weight, value, … entries (built by the preceding
ArrayNew; a transient codegen artifact, never observable).
Evidence-by-construction (§8): faults on a malformed pair row, a
non-int weight, or a non-positive weight — so a Weighted that
exists is always rollable.
RandRoll
[w] → T — one weighted draw from a Weighted[T] table. Total
over any table that exists (construction is the validator); writes
the RNG cell like every draw.
HeapPush
[a, x] → [a'] — push x into the min-heap maintained over the
array (sift-up; in-place-ness comes from the RMW write-back, the
SeqSorted precedent). §4b entry-check: DEV faults on a NaN in
the entering element; PROD places it by the pinned total order.
HeapPop
[a] → pushes Option[T] (the extracted minimum, none on
empty), then the shrunk re-heapified array on top of it — the
SeqPop stack contract, so the codegen take/store bracket writes
the array back and leaves the Option as the expression value.
HeapPeek
[a] → Option[T] — the minimum without extraction (none on
empty). Pure read.