Expand description
A collection of algorithms for searching within slices.
This module provides different search strategies and utilities to work with sorted slices. Currently, it supports binary and linear search algorithms, as well as an optimal search algorithm which picks between binary and linear searches depending on the size of the slice.
Structs§
- Binary
Search - Performs a binary search on a slice, with computational complexity
O(log n)
However, for small searches, a linear search may be faster. - Linear
Search - Performs a simple linear search on a slice, with computational complexity
O(n)
- Optimal
Search - Chooses between binary and linear search depending on the size of the slice to search
Traits§
- Search
- An algorithm for searching a sorted slice, e.g. Binary or Linear
Functions§
- lower_
bound - Returns the index of the largest element less than or equal to the search key.
- lower_
bound_ always - Returns the index of the biggest element less than or equal to the search key, or the first index.
- upper_
bound - Returns the index of the smallest element greater than or equal to the search key.
- upper_
bound_ always - Returns the index of the smallest element greater than or equal to the search key, or the last index.