33 #ifndef LIB_BINARY_SEARCH_H 34 #define LIB_BINARY_SEARCH_H 54 template<
class FUN,
typename PAR>
59 REQUIRE (lower <= upper);
60 while ((upper-lower) >= epsilon)
62 PAR div = (lower+upper) / 2;
69 return (lower+upper)/2;
79 template<
class FUN,
typename PAR>
83 REQUIRE (lower <= upper);
86 bool hit = fun(upper);
89 PAR len = (upper-lower);
90 lower = upper - len/10;
91 upper = lower + 14*len/10;
97 template<
class FUN,
typename PAR>
99 binarySearch (FUN&& fun, PAR lower, PAR upper, PAR epsilon)
101 REQUIRE (lower <= upper);
104 bool hit = fun(lower);
107 PAR len = (upper-lower);
108 upper = lower + len/10;
109 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