def plan
bend-edit-distance@0.2.2.0 · src/Batch.bend:123
import bend-edit-distance@0.2.2.0/src/Batch.bend as Batch
import Base
123def plan(fuel: Nat, jobs: List<&2, WeightedJob>) -> Plan:
124 match fuel jobs:
125 case _ Nil{}:
126 Empty{}
127 case _ WeightedJob{index, _, job} <> Nil{}:
128 Leaf{index, job}
129 case 0n values:
130 Serial{values}
131 case Succ{+p} +values:
132 +count = List.length(&2, WeightedJob, values)
133 +half = Nat.div(count, 2n)
134 plan_step(partition(values,
135 (Group{half, 0.0, Nil{}}, Group{Nat.sub(count, half), 0.0, Nil{}})),
136 left => right => Fork{plan(p, left), plan(p, right)})