pub struct BlockPlan { /* private fields */ }Expand description
A division of 0..count into fixed-size blocks.
§Examples
use molframe_core::parallel::BlockPlan;
let plan = BlockPlan::new(10, 4);
assert_eq!(plan.blocks(), 3);
assert_eq!(plan.range(0), Some(0..4));
assert_eq!(plan.range(2), Some(8..10));
assert_eq!(plan.range(3), None);Implementations§
Source§impl BlockPlan
impl BlockPlan
Sourcepub const fn new(count: usize, block: usize) -> Self
pub const fn new(count: usize, block: usize) -> Self
Divides count items into blocks of at most block items.
A zero block size is raised to one, because a plan that cannot advance is not a plan.
Sourcepub const fn with_default_block(count: usize) -> Self
pub const fn with_default_block(count: usize) -> Self
Divides count items using DEFAULT_BLOCK_ITEMS.
Sourcepub fn range(self, index: usize) -> Option<Range<usize>>
pub fn range(self, index: usize) -> Option<Range<usize>>
The half-open item range block index covers.
Sourcepub fn ranges(self) -> impl Iterator<Item = Range<usize>>
pub fn ranges(self) -> impl Iterator<Item = Range<usize>>
Every block range, in ascending index order.
Sourcepub fn useful_workers(self, requested: usize) -> usize
pub fn useful_workers(self, requested: usize) -> usize
How many workers can be usefully applied to this plan.
Never more than the number of blocks, because a worker with no block costs a thread and returns nothing.
Trait Implementations§
impl Copy for BlockPlan
impl Eq for BlockPlan
impl StructuralPartialEq for BlockPlan
Auto Trait Implementations§
impl Freeze for BlockPlan
impl RefUnwindSafe for BlockPlan
impl Send for BlockPlan
impl Sync for BlockPlan
impl Unpin for BlockPlan
impl UnsafeUnpin for BlockPlan
impl UnwindSafe for BlockPlan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more