pub struct PlanBudget { /* private fields */ }Expand description
Cumulative budget for a chain of solves.
Tracks both the strictest per-call class allowance (max_class)
and a count of remaining ops (remaining_ops). Each
[try_consume] either succeeds (decrementing remaining_ops,
updating worst_seen) or returns a BudgetExhausted error
the caller can use to short-circuit the chain.
Implementations§
Source§impl PlanBudget
impl PlanBudget
Sourcepub fn new(max_class: ComplexityClass, max_ops: usize) -> Self
pub fn new(max_class: ComplexityClass, max_ops: usize) -> Self
Construct a fresh budget with the given per-call class ceiling and op-count allowance.
Sourcepub fn try_consume(
&mut self,
class: ComplexityClass,
) -> Result<(), BudgetExhausted>
pub fn try_consume( &mut self, class: ComplexityClass, ) -> Result<(), BudgetExhausted>
Attempt to consume one slot for an operation of the given
class. Returns Ok(()) on success and decrements the
remaining-op count; returns Err(BudgetExhausted) if the
class exceeds the budget or no ops remain.
Sourcepub const fn remaining_ops(&self) -> usize
pub const fn remaining_ops(&self) -> usize
Number of op-slots still available.
Sourcepub const fn max_class(&self) -> ComplexityClass
pub const fn max_class(&self) -> ComplexityClass
Strictest per-call class allowed.
Sourcepub const fn worst_seen(&self) -> Option<ComplexityClass>
pub const fn worst_seen(&self) -> Option<ComplexityClass>
Highest class consumed so far across the chain, or None
if no ops have been consumed yet.
Sourcepub const fn has_capacity(&self) -> bool
pub const fn has_capacity(&self) -> bool
True iff the budget can still accept at least a Logarithmic
op — i.e. there are ops remaining (since Logarithmic is
the cheapest class and always within any sensible max_class).
Useful for “should I even try the next iteration?” loop guards.
Trait Implementations§
Source§impl Clone for PlanBudget
impl Clone for PlanBudget
Source§fn clone(&self) -> PlanBudget
fn clone(&self) -> PlanBudget
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more