template <class Iter, class Lambda> void CoPartition(Iter begin, Iter end, const Lambda& lambda, int min_chunk = CO_PARTITION_MIN, int max_chunk = CO_PARTITION_MAX)
template <class Range, class Lambda> void CoPartition(Range&& r, const Lambda& lambda)
Partitions a Range (possibly defined begin / end pair) into several subranges, based on number of CPU cores, and invokes lambda on them in parallel. begin / end variant passes new begin / end pair as lambda parameters, Range variant passes SubRange. Parallel processing is implemented by CoWork, which means CoWork::FinLock is available in lambda. If the input range has less than min_chunk elements, the operation is performed in callers thread. max_chunk limits the size of subrange passed to lambda.
template <class Range> ValueTypeOf<Range> CoSum(const Range& r, const ValueTypeOf<Range>& zero)
Returns the sum of all elements in range r, with zero representing initial zero value. T must have defined operator+=. Runs in parallel, operator+= must be reentrant.
template <class T> ValueTypeOf<T> CoSum(const T& c)
Same as CoSum(c, 0).
template <class Range, class V> int CoCount(const Range& r, const V& val)
Counts the number of elements in the Range r that are equal to val. Runs in parallel.
template <class Range, class Predicate> int CoCountIf(const Range& r, const Predicate& p)
Counts the number of elements in the Range r that satisfy condition p. Runs in parallel, p must be reentrant.
template <class Range, class Better> int CoFindBest(const Range& r, const Better& better)
Finds the most suitable element in a range r as specified by pred. E.g. if pred is std::less, finds minimum. If r is empty, returns -1. Runs in parallel, better must be reentrant.
template <class Range> int CoFindMin(const Range& r)
Returns the index of minimal element of r, using std::less to compare elements. If r is empty, returns -1. Runs in parallel, std::less must be reentrant.
template <class Range> const ValueTypeOf<Range>& CoMin(const Range& r)
Returns the value of minimal element of r, using std::less to compare elements. If r is empty, behavior is undefined (ASSERT fails in debug). Runs in parallel, std::less must be reentrant.
template <class Range> const ValueTypeOf<Range>& CoMin(const Range& r, const ValueTypeOf<Range>& def)
Returns the value of minimal element of r, using std::less to compare elements. If r is empty, returns def. Runs in parallel, std::less must be reentrant.
template <class Range> int CoFindMax(const Range& r)
Returns the index of maximal element of r, using std::greater to compare elements. If r is empty, returns -1. Runs in parallel, std::greater must be reentrant.
template <class Range> const ValueTypeOf<Range>& CoMax(const Range& r)
Returns the value of maximal element of r, using std::less to compare elements. If r is empty, behavior is undefined (ASSERT fails in debug). Runs in parallel, std::greater must be reentrant.
template <class Range> const ValueTypeOf<Range>& CoMax(const Range& r, const ValueTypeOf<Range>& def)
Returns the value of maximal element of r, using std::less to compare elements. If r is empty, returns def. Runs in parallel, std::greater must be reentrant.
template <class Range, class Match> int CoFindMatch(const Range& r, const Match& eq, int from = 0)
Returns the index of first element for which predicate match is true. If not found, returns -1. Search starts at index from. Runs in parallel, eq must be reentrant.
template <class Range, class V> int CoFindIndex(const Range& r, const V& value, int from = 0)
Returns the index of first element which is equal to value. If not found, returns -1. Search starts at index from. Runs in parallel, operator== must be reentrant.
template <class Range1, class Range2> int CoIsEqualRange(const Range1& r1, const Range2& r2)
Returns true if a and b are equal. operator== is used to compare elements. Ranges are considered equal if they have the same number of elements and for every element at index i: a[i] == b[i]. Runs in parallel, operator== must be reentrant.
template <class Range, class Predicate> Vector<int> CoFindAll(const Range& r, Predicate match, int from = 0)
Returns the Vector of indices of ALL elements for which match is true. Returned Vector is sorted in ascending order. Search starts at index from. Runs in parallel, match must be reentrant.
|