Internal scratch registers, phase memory invariants, and loop helpers #
Internal support module for the O(n³) Word-RAM Hungarian implementation, providing scratch
register indices, OuterMem, StepMem, reduced-cost arithmetic, and fillConst / exec_forLoop.
Current phase root row r.
Phase termination flag (0 while growing the tree, 1 once augmented).
Chosen minimum-slack unused column j₁.
Minimum slack δ = minv[j₁].
Matched row i₀ = colMate[j₁].
Primary loop index.
Secondary loop index / augmenting-path column cursor.
Scratch address register.
Scratch value register 1.
Scratch value register 2.
Scratch temporary register.
Between-phase memory representation of (y, z, mate) at layout bC.
yblock stores(vget y i).toNat.nzblock stores(-vget z j).toNat.colMateblock storesencodeOptFin (vget mate j).- hrow_some (j i : Fin n) : Lean.MaxFlow.vget mate j = some i → mem (bC + n * n + 7 * n + 1 + ↑i) = ↑j
Matched rows map to their matched column in
rowMate. - hrow_none (i : Fin n) : (∀ (j : Fin n), Lean.MaxFlow.vget mate j ≠ some i) → mem (bC + n * n + 7 * n + 1 + ↑i) = n
Unmatched rows hold sentinel
ninrowMate.
Within-phase memory representation of (s, bestRow) at layout bC.
- hused (j : Fin n) : mem (bC + n * n + 3 * n + ↑j) = if Lean.MaxFlow.vget s.used j = true then 1 else 0
usedblock stores0/1flags fors.used. - htree (i : Fin n) : mem (bC + n * n + 4 * n + ↑i) = if Lean.MaxFlow.vget s.tree i = true then 1 else 0
treeblock stores0/1flags fors.tree. minvblock stores(vget s.minv j).toNat.bestRowblock stores(bestRow j).val.
Reusable leaf loops #
Fill [dst, dst + n) with valReg.