42 #ifndef LIB_BINARY_SEARCH_H 43 #define LIB_BINARY_SEARCH_H 63 template<
class FUN,
typename PAR>
68 REQUIRE (lower <= upper);
69 while ((upper-lower) >= epsilon)
71 PAR div = (lower+upper) / 2;
78 return (lower+upper)/2;
88 template<
class FUN,
typename PAR>
92 REQUIRE (lower <= upper);
95 bool hit = fun(upper);
98 PAR len = (upper-lower);
99 lower = upper - len/10;
100 upper = lower + 14*len/10;
106 template<
class FUN,
typename PAR>
108 binarySearch (FUN&& fun, PAR lower, PAR upper, PAR epsilon)
110 REQUIRE (lower <= upper);
113 bool hit = fun(lower);
116 PAR len = (upper-lower);
117 upper = lower + len/10;
118 lower = upper - 14*len/10;
#define ASSERT_VALID_SIGNATURE(_FUN_, _SIG_)
Macro for a compile-time check to verify the given generic functors or lambdas expose some expected s...
Implementation namespace for support and library code.
Metaprogramming tools for transforming functor types.
auto binarySearch_upper(FUN &&fun, PAR lower, PAR upper, PAR epsilon)
entrance point to binary search to ensure the upper point indeed fulfils the test.
auto binarySearch_inner(FUN &&fun, PAR lower, PAR upper, PAR epsilon)
binary search: actual search loop