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>tostdlib/mo.cp, keepingmo_orderpublic as the escape hatch (andmo_stepsfor existing callers).mowalksmo_order(queries)with in-place 4-pointer loops (add/removeO((n + q)·√n) times,answer(qi)qtimes withqueries[qi]active), returning results in original query order with zero per-query step-list allocation and zerostd::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"):cf2006ddrops from2.1x(430–470 ms) to1.34x(271.8 msvs202.4 ms), andcf2129edrops its hand-written 4-loop Mo driver (575.4 msvs452.6 ms,1.27x). Separateadd/removeclosures avoid encoding two distinct events behind a±1sentinel, andanswer: Int -> RmatchesTimeTree.runso queries carrying extra per-query data (likecf2129e'sk) work without duplicating the window. - Reverse. Remove
pub fn mofromstdlib/mo.cpand revertcf2006d.cp/cf2129e.cptomo_order+ manual loops.