AngouriMath

Navigation

BudgetLedger


← Back to list of classes

Description

Summary

The accounting side of a WorkBudget: what has been spent so far, and
what stopped the computation if anything has.

Remarks

Mutable, and single-flow, on purpose. The limits are an immutable value so
that they can be shared; the drawing-down is one object mutated in program order.
The alternative — threading a remaining count through as an immutable value — has to
split the count at every branch of a search, and there is no right split: an
even one starves the branch that needed the work, giving it all to the first starves
the rest, and a branch that fails then needs a protocol for handing back what it did
not spend. A single ledger drawn down in program order needs none of that, is exactly
reproducible as long as the algorithm's own order is defined — which
#746's third
design principle requires anyway — and bounds the search as a whole rather than each
branch of it, which is the difference between a bound and a suggestion.
A subgoal inherits the ledger rather than getting one. Passing the same object
down is what makes a call bounded end to end. Giving each stage a budget of its own
bounds each stage and leaves the whole unbounded, which is how
#896 arose:
the same call is bounded or not depending on which internal path accepted it, and
that is worse to debug than either extreme.
Honouring is cooperative, so no thread is involved. The algorithm asks —
Spend(System.Int64) before doing a unit of work, Require(System.Boolean,System.String) before letting
a structure grow — and declines when told to. Nothing is interrupted, nothing is
aborted, and there is no second thread to make the answer depend on scheduling. The
cost is that an algorithm which does not ask cannot be bounded, which is the honest
trade: a bound that is enforced from outside is a thread abort, and a thread abort in
the middle of a rewrite leaves no answer worth having.
The first ceiling to fire is the one reported. Once one has, every subsequent
question answers "no" without re-testing, so the reason cannot be overwritten by
whatever the algorithm happened to ask next on its way out.

Members

























Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 4378 pages online