bisector

Struct Bisector

Source
pub struct Bisector<'v, T> { /* private fields */ }
Expand description

Stateless implementation of the bisection method.

Implementations§

Source§

impl<'v, T> Bisector<'v, T>

Source

pub fn new(view: &'v [T]) -> Self

Create a new Bisector for a given view.

Source

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.

Source

pub fn bisect<F, L, R>(&self, f: F, indices: Indices) -> Step<L, R>
where F: FnOnce(&T) -> ConvergeTo<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:

Source

pub fn try_bisect<F, E, L, R>( &self, f: F, indices: Indices, ) -> Result<Step<L, R>, E>
where F: FnOnce(&T) -> Result<ConvergeTo<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.

Trait Implementations§

Source§

impl<'v, T: Debug> Debug for Bisector<'v, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'v, T> Freeze for Bisector<'v, T>

§

impl<'v, T> RefUnwindSafe for Bisector<'v, T>
where T: RefUnwindSafe,

§

impl<'v, T> Send for Bisector<'v, T>
where T: Sync,

§

impl<'v, T> Sync for Bisector<'v, T>
where T: Sync,

§

impl<'v, T> Unpin for Bisector<'v, T>

§

impl<'v, T> UnwindSafe for Bisector<'v, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.