Function binary_search_i
Summary
#include <include/EASTL/algorithm.h>
(1) template <typename ForwardIterator, typename T>
ForwardIterator binary_search_i(ForwardIterator first, ForwardIterator last, const T &value)
(2) template <typename ForwardIterator, typename T, typename Compare>
ForwardIterator binary_search_i(ForwardIterator first, ForwardIterator last, const T &value, Compare compare)
Function overload
Synopsis
#include <include/EASTL/algorithm.h>
template <typename ForwardIterator, typename T>
ForwardIterator binary_search_i(ForwardIterator first, ForwardIterator last, const T &value)
Description
Returns: iterator if there is an iterator i in the range [first last) that satisfies the corresponding conditions: !(*i < value) && !(value < *i). Returns last if the value is not found.
Complexity: At most 'log(last - first) + 2' comparisons.
Mentioned in
Source
Lines 3055-3064 in include/EASTL/algorithm.h.
template <typename ForwardIterator, typename T>
inline ForwardIterator
binary_search_i(ForwardIterator first, ForwardIterator last, const T& value)
{
// To do: This can be made slightly faster by not using lower_bound.
ForwardIterator i(eastl::lower_bound<ForwardIterator, T>(first, last, value));
if((i != last) && !(value < *i)) // Note that we always express value comparisons in terms of < or ==.
return i;
return last;
}
Synopsis
#include <include/EASTL/algorithm.h>
template <typename ForwardIterator, typename T, typename Compare>
ForwardIterator binary_search_i(ForwardIterator first, ForwardIterator last, const T &value, Compare compare)
Description
Returns: iterator if there is an iterator i in the range [first last) that satisfies the corresponding conditions: !(*i < value) && !(value < *i). Returns last if the value is not found.
Complexity: At most 'log(last - first) + 2' comparisons.
Mentioned in
Source
Lines 3075-3084 in include/EASTL/algorithm.h.
template <typename ForwardIterator, typename T, typename Compare>
inline ForwardIterator
binary_search_i(ForwardIterator first, ForwardIterator last, const T& value, Compare compare)
{
// To do: This can be made slightly faster by not using lower_bound.
ForwardIterator i(eastl::lower_bound<ForwardIterator, T, Compare>(first, last, value, compare));
if((i != last) && !compare(value, *i))
return i;
return last;
}