commit b78b3ffe122b19ce969e2267dc4dd49184e66f05
parent fe6e745c3ba0b4d7bf7475fa0beb31a20b949626
Author: triesap <tyson@radroots.org>
Date: Mon, 21 Sep 2026 13:55:21 +0000
core: implement bounded single-line allocation
Diffstat:
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/src/hyf_application/match_plan.mojo b/src/hyf_application/match_plan.mojo
@@ -52,3 +52,20 @@ def allocate_single_line(
def multi_supplier_is_supported() -> Bool:
return False
+
+
+@fieldwise_init
+struct PlannerBounds(Copyable, Movable):
+ var max_candidates: Int
+ var max_plans: Int
+
+
+def planner_bounds(max_candidates: Int, max_plans: Int) raises -> PlannerBounds:
+ if max_candidates <= 0 or max_plans <= 0:
+ raise Error("planner bounds must be positive")
+ return PlannerBounds(max_candidates=max_candidates, max_plans=max_plans)
+
+
+def enforce_plan_bound(plan_count: Int, bounds: PlannerBounds) raises:
+ if plan_count > bounds.max_plans:
+ raise Error("plan enumeration exceeds the bound")
diff --git a/tests/test_application.mojo b/tests/test_application.mojo
@@ -536,3 +536,16 @@ def test_supplier_grouping_and_bounded_allocation() raises:
assert_equal(len(plan.allocations), 2)
assert_equal(len(plan_conservation_violations(plan, capacities)), 0)
assert_true(not multi_supplier_is_supported())
+
+
+from hyf_application.match_plan import PlannerBounds, enforce_plan_bound, planner_bounds
+
+
+def test_bounded_single_line_allocation() raises:
+ var bounds = planner_bounds(10, 3)
+ assert_equal(bounds.max_plans, 3)
+ enforce_plan_bound(2, bounds)
+ with assert_raises():
+ enforce_plan_bound(4, bounds)
+ with assert_raises():
+ _ = planner_bounds(0, 3)