pub struct Geometric<const N: usize> { /* private fields */ }Expand description
A geometric restart strategy.
The interval between restarts is multiplied by a constant factor N (where N > 1 for
increasing intervals) after each restart.
The sequence of intervals is initial, initial*N, initial*N*N, ....
Here, initial seems to be 1 based on restarts_interval: 1 and then it’s multiplied by N.
The first interval will be 1 (due to restarts_in: 0 and restarts_interval: 1 upon first restart),
then N, then N*N, etc.
The generic constant N is the geometric factor.
Trait Implementations§
Source§impl<const N: usize> Restarter for Geometric<N>
impl<const N: usize> Restarter for Geometric<N>
Source§fn new() -> Self
fn new() -> Self
Creates a new Geometric restarter.
restarts_in is initialised to 0, meaning it will restart on the first call to should_restart().
The first interval after the initial restart will be 1, the next will be 1*N, then 1*N*N, etc.
Source§fn restart(&mut self)
fn restart(&mut self)
Performs a restart:
- Increments the restart count.
- Sets
restarts_into the currentrestarts_interval. - Updates
restarts_intervalby multiplying it byNfor the next cycle.
Source§fn should_restart(&mut self) -> bool
fn should_restart(&mut self) -> bool
Overrides the default should_restart from the trait.
This implementation is identical to the default one but is explicitly written out.
If restarts_in is 0, it calls restart() and returns true.
Otherwise, it decrements restarts_in and returns false.
Source§fn restarts_in(&self) -> usize
fn restarts_in(&self) -> usize
Source§fn increment_restarts_in(&mut self)
fn increment_restarts_in(&mut self)
Source§fn num_restarts(&self) -> usize
fn num_restarts(&self) -> usize
impl<const N: usize> Eq for Geometric<N>
impl<const N: usize> StructuralPartialEq for Geometric<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for Geometric<N>
impl<const N: usize> RefUnwindSafe for Geometric<N>
impl<const N: usize> Send for Geometric<N>
impl<const N: usize> Sync for Geometric<N>
impl<const N: usize> Unpin for Geometric<N>
impl<const N: usize> UnwindSafe for Geometric<N>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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