Design decisions

121. In-place std.mo.mo driver with separate add/remove closures (2026-11-21)

  • Decision. Add pub fn mo<D, R>(queries: List<Range<D>>, add: D -> (), remove: D -> (), answer: Int -> R) -> List<R> to stdlib/mo.cp, keeping mo_order public as the escape hatch (and mo_steps for existing callers). mo walks mo_order(queries) with in-place 4-pointer loops (add/remove O((n + q)·√n) times, answer(qi) q times with queries[qi] active), returning results in original query order with zero per-query step-list allocation and zero std::function (all callbacks lower statically).
  • Reason. Closes both high frictions in research/frictions/cf2006d.md ("Mo's algorithm has no driver" and "The port runs 2.1x the original on the max input"): cf2006d drops from 2.1x (430–470 ms) to 1.34x (271.8 ms vs 202.4 ms), and cf2129e drops its hand-written 4-loop Mo driver (575.4 ms vs 452.6 ms, 1.27x). Separate add/remove closures avoid encoding two distinct events behind a ±1 sentinel, and answer: Int -> R matches TimeTree.run so queries carrying extra per-query data (like cf2129e's k) work without duplicating the window.
  • Reverse. Remove pub fn mo from stdlib/mo.cp and revert cf2006d.cp / cf2129e.cp to mo_order + manual loops.