Skip to main content

batch_decision

Function batch_decision 

Source
pub fn batch_decision(
    policy: &BatchPolicy,
    budget: NonZeroUsize,
    query: &BatchQuery,
) -> BatchDecision
Expand description

Decide the route for one batch on budget threads under policy.

Forced strategies are clamped (lanes <= min(items, budget), lanes * item_threads <= budget) but never fall back. Auto narrows the budget first (see the module docs) and uses the original budget only for the forced strategies.

Whether a route can run the returned decision is the route’s own preflight: a decision with both lanes and item threads is honoured or refused before any output write, never partially applied (see BatchDecision’s route contract).

§Examples

use std::num::NonZeroUsize;
use tcontract_exec::batch::{batch_decision, BatchPolicy, BatchQuery, BatchStrategy};

let budget = NonZeroUsize::new(4).unwrap();
let query = BatchQuery::new(2, 1024.0);
let split = BatchPolicy::new(BatchStrategy::Split {
    lanes: NonZeroUsize::new(8).unwrap(),
});
let d = batch_decision(&split, budget, &query);
// Clamped to the items and the budget.
assert_eq!((d.lanes, d.item_threads), (2, 2));