Skip to main content

ExactSearch

Trait ExactSearch 

Source
pub trait ExactSearch {
    type Item;

    // Required methods
    fn exact_search(&self, x: &Self::Item) -> Result<usize, usize>
       where Self::Item: Ord;
    fn exact_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
       where F: FnMut(&'a Self::Item) -> Ordering;
    fn exact_search_by_key<'a, K, F>(
        &'a self,
        key: &K,
        f: F,
    ) -> Result<usize, usize>
       where F: FnMut(&'a Self::Item) -> K,
             K: Ord;
}
Expand description

Exact search for ordered slices with an early equality exit and branchless search-direction selection.

This combines the useful properties of a conventional early-exit binary search with the conditional selection used by modern standard-library binary search implementations. It returns either a matching index or the position where the value can be inserted while preserving order.

Required Associated Types§

Required Methods§

Searches for x, returning a matching index or its insertion position.

Source

fn exact_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
where F: FnMut(&'a Self::Item) -> Ordering,

Searches with a comparator, returning a match or insertion position.

Source

fn exact_search_by_key<'a, K, F>( &'a self, key: &K, f: F, ) -> Result<usize, usize>
where F: FnMut(&'a Self::Item) -> K, K: Ord,

Searches by an extracted key, returning a match or insertion position.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> ExactSearch for [T]

Source§

type Item = T

Source§

fn exact_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
where F: FnMut(&'a Self::Item) -> Ordering,

Source§

fn exact_search_by_key<'a, K, F>( &'a self, key: &K, f: F, ) -> Result<usize, usize>
where F: FnMut(&'a Self::Item) -> K, K: Ord,

Implementors§