Function split_range

Source
pub fn split_range(
    total: usize,
    min_batch_size: usize,
    max_batch_size: usize,
) -> Result<Vec<(usize, usize, usize)>, String>
Expand description

Generates a range of possible split configurations based on a min and max batch size.

§Arguments

  • total - The total number to be split.
  • min_batch_size - The minimum allowed size for each batch.
  • max_batch_size - The maximum allowed size for each batch.

§Returns

A Result containing a vector of tuples, each representing a possible split configuration: (number of batches, batch size, remainder)

§Errors

Returns an error if:

  • The total is zero.
  • The min_batch_size is zero.
  • The max_batch_size is less than min_batch_size.

§Examples

use batch_maestro::split_range;

let configurations = split_range(100, 20, 40).unwrap();
assert_eq!(configurations, vec![(3, 33, 1), (4, 25, 0), (5, 20, 0)]);