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 RangeInclusivecmpr
to sample and compare data to captured target.
Required Methods§
sourcefn binary_by(self, cmpr: impl FnMut(T) -> Ordering) -> Result<T, T>
fn binary_by(self, cmpr: impl FnMut(T) -> Ordering) -> Result<T, T>
Unchecked first Ok(hit) or Err(insert order for a missing item).
sourcefn binary_any(&self, cmpr: impl FnMut(T) -> Ordering) -> (T, Range<T>)
fn binary_any(&self, cmpr: impl FnMut(T) -> Ordering) -> (T, Range<T>)
Unchecked first hit or insert order, and the final search range.
sourcefn binary_all(&self, cmpr: impl FnMut(T) -> Ordering) -> Range<T>
fn binary_all(&self, cmpr: impl FnMut(T) -> Ordering) -> Range<T>
General Binary Search, returns the range of all matching items
Object Safety§
Implementations on Foreign Types§
source§impl<T> Search<T> for RangeInclusive<T>
impl<T> Search<T> for RangeInclusive<T>
source§fn binary_by(self, cmpr: impl FnMut(T) -> Ordering) -> Result<T, T>
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>)
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>
fn binary_all(&self, cmpr: impl FnMut(T) -> Ordering) -> Range<T>
General Binary Search for finding all the matches.
Searches within the specified RangeInclusivecmpr
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.