pub struct Bisector<'v, T> { /* private fields */ }
Expand description
Stateless implementation of the bisection method.
Implementations§
Source§impl<'v, T> Bisector<'v, T>
impl<'v, T> Bisector<'v, T>
Sourcepub fn view(&self) -> &'v [T]
pub fn view(&self) -> &'v [T]
A view of the slice as known to the bisector.
NB: This is always the complete view, regardless of any bisection steps which might have taken place.
Sourcepub fn bisect<F, L, R>(&self, f: F, indices: Indices) -> Step<L, R>
pub fn bisect<F, L, R>(&self, f: F, indices: Indices) -> Step<L, R>
Stateless implementation of the bisection method.
This method takes a convergence function f
and indices indices
.
The convergence function f
is used to determine towards which side of the current view, the
bisection should progress.
Since this implementation is stateless, no internal state about the progression is stored.
Instead, indices of point from which the bisection method should be applied must be provided.
The method returns a Step
struct as output. This indices
property of this struct contains
the indices which point to the view to which the convergence function f
converged, during
this step. In other words, the Step::indices
may be used as input for the indices
parameter
for the next bisection iteration.
As also described above, the indices
argument must be the left and right index which point
to the view used by the current step of the bisection. The left and right index must be valid
indices for the slice held by the Bisector
(also called the view
).
See also:
Bisector::try_bisect
: A variant ofbisect
which can be used when the convergence function is fallible.
Sourcepub fn try_bisect<F, E, L, R>(
&self,
f: F,
indices: Indices,
) -> Result<Step<L, R>, E>
pub fn try_bisect<F, E, L, R>( &self, f: F, indices: Indices, ) -> Result<Step<L, R>, E>
This method can be used when the convergence function is fallible.
Otherwise exactly the same as Bisector::bisect
.
When the bisection is already in a converged state for the given indices, the method returns with an Ok Result.