Documentation of CSL
dichotomy.h
1 #pragma once
2 
3 namespace csl {
4 
21 template<class Iterator, class Comparator>
22 Iterator dichotomyFindIf(
23  Iterator first,
24  Iterator last,
25  Comparator &&f
26  )
27 {
28  while (last != first) {
29  const auto diff = last - first;
30  Iterator mid = first + diff/2;
31  // auto const &midExpr = v[mid]->getEncapsulated();
32  int comp = f(*mid);
33  if (comp == 1)
34  last = mid;
35  else if (comp == -1) {
36  if (mid == first)
37  ++first;
38  else
39  first = mid;
40  }
41  else
42  return mid;
43  if (first + 1 == mid) {
44  return (f(*first) == 1) ? first : mid;
45  }
46  }
47  return first;
48 }
49 
50 }
Namespace for csl library.
Definition: abreviation.h:34
Bunch of functions that allow to do comparisons with Arbitrary expressions or expressions with dummy ...
Definition: comparison.h:115
Iterator dichotomyFindIf(Iterator first, Iterator last, Comparator &&f)
Template dichotomy algorithm using a comparator.
Definition: dichotomy.h:22