44. Containers area design (§4.8–4.9, 2026-11-21)
- 44.1
SortedBagcursors are read-only opaque handles (BagCursor) with O(1) amortizednext_cursor/prev_cursor, plusentries()/entries_rev()generators.SortedBagadds parent pointers and a recycled free list so removed nodes do not leak RSS (cf2066e.md#1, #2). Cursors stay read-only rather than supporting erase-by-cursor because treap split/merge invalidates structural paths and O(log n) erase by key is already fast; the hot path incf2066eis O(1)-per-step local walking (entries_rev+prev/next).OrderedSet<K>is its unique-key twin withrank,count_range, andfirst_where(cf2262b.md). Reverse: dropBagCursorand parent pointers fromstdlib/bag.cp.
- 44.2
IntervalMap<D, T>.assignreturnsList<(range: Range<D>, val: T)>, not ayieldsgenerator. Returning the overwritten runs guarantees the maximal-run partition invariant always holds even if the callerbreaks orreturns early, and costs zero extra asymptotic time because total overwritten runs acrossqcalls is O(n + q). Built directly overRange<D>so callers stay in their nominal domain (tree.Pre,cf2237h.md). Reverse: changeassigntoyieldsonce mutating generators guarantee post-break cleanup.
- 44.3
Bitset.subset_sums<D>uses binary-carry grouping;shift_ormutates in place. Naivereach.union(reach.shifted(w))allocates per item and hits a 10x TLE on duplicate weights (cf2187d.md).shift_or(k)eliminates per-step allocation for custom shift DPs, andsubset_sums<D>(weights)provides the O(K sqrt(S) / 64) binary-carry knapsack in stdlib. Reverse: removesubset_sumsorshift_orfromstdlib/bitset.cp.
- 44.4
PotentialDsu<V>andRollbackArray<D, T>sharestd.dsu.Mark. All rollbackable structures instd.dsuuse the same nominalMarkhandle andmark()/undo_to(snap)protocol so multi-structure divide-and-conquer rollback is uniform. Reverse: movePotentialDsu/RollbackArrayback toexamples/local-lib/ds/.
- 44.5
FlatMap<V>instd.hashmapis an explicit opt-in open-addressingInthash table. BuiltinHashMap<K, V>remains the default for arbitrary keys;FlatMap<V>uses per-instance saltedsplitmix64and backward-shift deletion for low RSS and cache locality on largeIntkey sets without silently substituting forHashMap. Reverse: removestdlib/hashmap.cp.