47 template<
typename CONTAINER>
48 inline void safeForEach(CONTAINER &container, std::function<
void(
typename CONTAINER::value_type)> func) {
49 for (
auto it = container.begin(); it != container.end();) {
61 template<
typename CONTAINER>
62 inline bool safeTestForEach(CONTAINER &container, std::function<
bool(
typename CONTAINER::value_type)> func) {
63 for (
auto it = container.begin(); it != container.end();) {
82 template<
class LIST,
class COMPARER>
85 const int n = L.size();
89 for (
const typename LIST::value_type &x : L)
95 for (
typename LIST::value_type &x : L)
106 template<
typename CONTAINER,
typename TYPE,
typename ITERATOR>
108 CONTAINER &container,
109 std::function<
bool(
const TYPE &)> includeElement) {
112 for(
const auto &e : container) {
113 nElements += includeElement(e) ? 1 : 0;
116 ITERATOR result = container.end();
122 for (ITERATOR it = container.begin(); result == container.end(); it++) {
123 if(includeElement(*it)) {
126 if(elemCounter == chosenElement) {
141 template<
typename CONTAINER,
typename TYPE,
typename ITERATOR>
143 CONTAINER &container,
144 std::function<
bool(
const TYPE &)> includeElement,
149 for (ITERATOR it = container.begin(); it != container.end(); it++) {
156 ITERATOR result = container.end();
158 for (
auto it : other) {
159 if (includeElement(*it)) {
187 template<
typename CONTAINER,
typename TYPE,
typename ITERATOR>
189 CONTAINER &container,
190 std::function<
bool(
const TYPE &)> includeElement,
192 ITERATOR result = container.begin();
193 int size = container.size();
199 for (
int i = 0; i < index; i++) {
204 if (!includeElement(*result)) {
206 result = chooseIteratorByFastTest<CONTAINER, TYPE, ITERATOR>(container, includeElement);
208 result = chooseIteratorBySlowTest<CONTAINER, TYPE, ITERATOR>(container, includeElement, size);
220 template<
typename CONTAINER,
typename TYPE>
222 CONTAINER &container,
223 std::function<
bool(
const TYPE&)> includeElement = [](
const TYPE&) {
return true; },
224 bool isFastTest =
true) {
226 <CONTAINER, TYPE,
typename CONTAINER::iterator>(container, includeElement, isFastTest);
230 template<
typename CONTAINER,
typename TYPE>
232 const CONTAINER &container,
233 std::function<
bool(
const TYPE&)> includeElement = [](
const TYPE&) {
return true; },
234 bool isFastTest =
true) {
236 <
const CONTAINER, TYPE,
typename CONTAINER::const_iterator>(container, includeElement, isFastTest);
ITERATOR chooseIteratorByFastTest(CONTAINER &container, std::function< bool(const TYPE &)> includeElement)
The parameterized class Array implements dynamic arrays of type E.
void quicksortTemplate(LIST &L)
bool safeTestForEach(CONTAINER &container, std::function< bool(typename CONTAINER::value_type)> func)
Like ogdf::safeForEach() but aborts if func returns false.
int randomNumber(int low, int high)
Returns random integer between low and high (including).
ITERATOR chooseIteratorFrom(CONTAINER &container, std::function< bool(const TYPE &)> includeElement, bool isFastTest)
Returns an iterator to a random element in the container.
Declaration and implementation of Array class and Array algorithms.
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
Standard comparer (valid as a static comparer).
ITERATOR chooseIteratorBySlowTest(CONTAINER &container, std::function< bool(const TYPE &)> includeElement, int size)
void quicksort()
Sorts array using Quicksort.
void safeForEach(CONTAINER &container, std::function< void(typename CONTAINER::value_type)> func)
Calls (possibly destructive) func for each element of container.
The namespace for all OGDF objects.