Trait SearchSorted

Source
pub trait SearchSorted<T> {
    // Required method
    fn search_sorted_by<F: FnMut(usize) -> Ordering, N: FnMut(usize) -> Ordering>(
        &self,
        find: F,
        side_find: N,
        side: SearchSortedSide,
    ) -> SearchResult;

    // Provided methods
    fn search_sorted_many<I: IntoIterator<Item = T>>(
        &self,
        values: I,
        side: SearchSortedSide,
    ) -> impl Iterator<Item = SearchResult>
       where Self: IndexOrd<T> { ... }
    fn search_sorted(&self, value: &T, side: SearchSortedSide) -> SearchResult
       where Self: IndexOrd<T> { ... }
}
Expand description

Searches for value assuming the array is sorted.

Returned indices satisfy following condition if the search for value was to be inserted into the array at found positions

sideresult satisfies
leftarray[i-1] < value <= array[i]
rightarray[i-1] <= value < array[i]

Required Methods§

Source

fn search_sorted_by<F: FnMut(usize) -> Ordering, N: FnMut(usize) -> Ordering>( &self, find: F, side_find: N, side: SearchSortedSide, ) -> SearchResult

find function is used to find the element if it exists, if element exists side_find will be used to find desired index amongst equal values

Provided Methods§

Source

fn search_sorted_many<I: IntoIterator<Item = T>>( &self, values: I, side: SearchSortedSide, ) -> impl Iterator<Item = SearchResult>
where Self: IndexOrd<T>,

Source

fn search_sorted(&self, value: &T, side: SearchSortedSide) -> SearchResult
where Self: IndexOrd<T>,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S, T> SearchSorted<T> for S
where S: IndexOrd<T> + ?Sized,