shareOf function

(int, int) shareOf(
  1. int count,
  2. int index,
  3. int shards, {
  4. int align = 1,
})

The contiguous share [start, end) of count items that shard index of shards owns, with inner boundaries rounded down to a multiple of align.

Implementation

(int, int) shareOf(int count, int index, int shards, {int align = 1}) {
  int boundary(int w) =>
      w == shards ? count : (count * w ~/ shards) ~/ align * align;
  return (boundary(index), boundary(index + 1));
}