Trait indxvec::Binarysearch

source ·
pub trait Binarysearch<T, U> {
    // Required methods
    fn find_any(
        self,
        sample: &mut impl FnMut(&T) -> U,
        target: U
    ) -> (T, Range<T>);
    fn find_all(self, sample: &mut impl FnMut(&T) -> U, target: U) -> Range<T>;
}
Expand description

Binary search algoritms implemented on RangeInclusive

Required Methods§

source

fn find_any(self, sample: &mut impl FnMut(&T) -> U, target: U) -> (T, Range<T>)

Binary search for target, returns the index of the first match and its bounds

source

fn find_all(self, sample: &mut impl FnMut(&T) -> U, target: U) -> Range<T>

Binary search for target, returns full range of all matches

Implementations on Foreign Types§

source§

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

source§

fn find_any(self, sample: &mut impl FnMut(&T) -> U, target: U) -> (T, Range<T>)

Binary search for an index of any item matching the target.
Searches the specified RangeInclusive.
Closure sample returns data items of generic type U from any source. The sort order of the data can be either ascending or descending, it is automatically detected. Returns the index of the first hit that is PartiallyEqual to the target and its last enclosing interval lo..hi.
When the target is not found, then (ip, lo..ip) is returned, where ip is the target’s insert position (index) and lo is the last lower bound. The (indexing) range values can be of any generic type T satisfying the listed trait bounds. Typically usize for searching efficiently in-memory, u128 for searching whole disks or the internet, or f64 for solving nonlinear equations.

source§

fn find_all(self, sample: &mut impl FnMut(&T) -> U, target: U) -> Range<T>

General Binary Search. Fast nethod for finding all the matches of target (the last argument).
Search within the specified Range<T> where range.start <= range.end.
Range<T> indexing values can be of any generic type satisfying the listed bounds. Typically usize for indexing efficiently in-memory, u128 for searching whole disks or internet, etc. Closure sample fetches individual items from the (sorted) data source.
The sort order of the data can be either ascending or descending. It is automatically detected. When the target is in sort order before self.start, empty self.start..self.start range is returned. When the target is in sort 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 returns the range of all consecutive values PartiallyEqual to the target.

Implementors§