Function optimize_split

Source
pub fn optimize_split(
    total: usize,
    min_batches: usize,
    max_batches: usize,
) -> Result<(usize, Vec<NonZeroUsize>), String>
Expand description

Finds the most even split possible within a given range of batch counts.

§Arguments

  • total - The total number to be split.
  • min_batches - The minimum number of batches.
  • max_batches - The maximum number of batches.

§Returns

A Result containing a tuple with:

  1. The number of batches.
  2. A vector of NonZeroUsize representing the size of each batch.

§Errors

Returns an error if:

  • The total is zero.
  • The min_batches is zero.
  • The max_batches is less than min_batches.

§Examples

use batch_maestro::optimize_split;
use std::num::NonZeroUsize;

let (num_batches, batch_sizes) = optimize_split(100, 3, 5).unwrap();
assert_eq!(num_batches, 4);
assert_eq!(batch_sizes, vec![NonZeroUsize::new(25).unwrap(); 4]);