Trait indxvec::Search

source ·
pub trait Search<T> {
    // Required methods
    fn binary_by(self, cmpr: impl FnMut(T) -> Ordering) -> Result<T, T>;
    fn binary_any(&self, cmpr: impl FnMut(T) -> Ordering) -> (T, Range<T>);
    fn binary_all(&self, cmpr: impl FnMut(T) -> Ordering) -> Range<T>;
}
Expand description

Binary search algoritms implemented on RangeInclusive. Using a closure cmpr to sample and compare data to captured target.

Required Methods§

source

fn binary_by(self, cmpr: impl FnMut(T) -> Ordering) -> Result<T, T>

Unchecked first Ok(hit) or Err(insert order for a missing item).

source

fn binary_any(&self, cmpr: impl FnMut(T) -> Ordering) -> (T, Range<T>)

Unchecked first hit or insert order, and the final search range.

source

fn binary_all(&self, cmpr: impl FnMut(T) -> Ordering) -> Range<T>

General Binary Search, returns the range of all matching items

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> Search<T> for RangeInclusive<T>
where T: PartialOrd + Copy + From<u8> + Add<Output = T> + Sub<Output = T> + Div<Output = T>,

source§

fn binary_by(self, cmpr: impl FnMut(T) -> Ordering) -> Result<T, T>

Binary search within an inclusive range.
When the target is missing, returns the insert position as Err<T>. Same as std::slice::binary_search_by() but does not need explicit data. The probing of any data is done by the comparator closure.

source§

fn binary_any(&self, cmpr: impl FnMut(T) -> Ordering) -> (T, Range<T>)

Binary search for an index of any item matching the target within an open interval specified in the input inclusive range. Closure cmpr probes some ordered data and compares it against some target. This code is agnostic about the type of the target (and the data). Descending order data can be handled by reversing the order of the comparison operands in the call. Returns the index of the first hit that is PartiallyEqual to the target and its last search envelope lo..hi.
When the target is not found, then (ip, lo..ip) is returned, where ip is the target’s insert position. The (indexing) range values can be of any generic type T, satisfying the listed trait bounds. Typically usize for searching in-memory, u128 for searching disks or internet, or f64 for numerically solving nonlinear equations.

source§

fn binary_all(&self, cmpr: impl FnMut(T) -> Ordering) -> Range<T>

General Binary Search for finding all the matches. Searches within the specified RangeInclusive index. The (indexing) range values can be of any generic type T (satisfying the listed bounds): usize for indexing in-memory, u128 for searching whole disks or internet, f64 for solving equations which might not converge using other methods. Comparator closure cmpr is comparing data against a target captured from its environment. Using closures enables custom comparisons of user’s own data types. This code is also agnostic about the type of the target (and of the data). When the target is in order before self.start, empty self.start..self.start range is returned. When the target is in order after self.end, self.end..self.end is returned. When target is not found, then ip..ip is returned, where ip is its insert position. Otherwise the range of all consecutive values PartiallyEqual to the target is returned.

Implementors§