|
A number of generic algorithms.
template <class T> void Swap(T& a, T& b)
Swaps values. Specific types might specialize Swap with more effective variants.
T must have either deep copy operator or pick operator.
template <class I> void IterSwap(I a, I b)
Swaps values pointed to by iterators. Specific types might specialize IterSwap with more effective variants.
Swap must be defined for type pointed to by I.
|
a |
Iterator pointing to first value. |
|
b |
Iterator pointing to second value. xx |
template <class C, class T, class L> int FindLowerBound(const C& v, int pos, int count, const T& val, const L& less)
Finds first position in range of container sorted by less predicate where val can be inserted without breaking the ordering.
|
count |
Number of elements in range. |
|
Return value |
Position in container. |
template <class T> int sgn(T a)
Returns 1 if a. is greater than zero, -1 if a is smaller than zero and zero if a is zero.
template <class T> T tabs(T a)
Returns the absolute value of a.
template <class T> int cmp(const T& a, const T& b)
Returns 1 if a is greater than b, -1 if a is smaller than b and zero if a is equal than b.
template <class I> void Reverse(I start, I end)
Reverses the values of a C array that begins in start and ends in end.
template <class T, class V> void Sum(V& sum, T ptr, T end)
Returns in sum the sum of the values of a C array that begins in ptr and ends in end.
template <class T> T MinElement(T ptr, T end)
Returns the value of the min element of a C array that begins in ptr and ends in end.
template <class T> T MaxElement(T ptr, T end)
Returns the value of the max element of a C array that begins in ptr and ends in end.
template <class C, class T, class L> int FindLowerBound(const C& v, const T& val, const L& less)
Finds first position in sorted by less predicate where val can be inserted without breaking the ordering.
|
Return value |
Position in container. |
template <class C, class T> int FindLowerBound(const C& v, const T& val)
Finds first position in sorted by operator< predicate where val can be inserted without breaking the ordering.
|
Return value |
Position in container. |
template <class C, class T, class L> int FindUpperBound(const C& v, int pos, int count, const T& val, const L& less)
Finds last position in range of container sorted by less predicate where val can be inserted without breaking the ordering.
|
count |
Number of elements in range. |
|
Return value |
Position in container. |
template <class C, class T, class L> int FindUpperBound(const C& v, const T& val, const L& less)
Finds last position in sorted by less predicate where val can be inserted without breaking the ordering.
|
Return value |
Position in container. |
template <class C, class T> int FindUpperBound(const C& v, const T& val)
Finds last position in sorted by operator< predicate where val can be inserted without breaking the ordering.
|
Return value |
Position in container. |
template <class C, class T, class L> int FindBinary(const C& v, const T& val, int pos, int count, const L& less)
Finds position of element with specified value in a range of container sorted by less predicate. If no such element exists, a negative value is returned.
|
count |
Number of elements in range. |
|
Return value |
Position in container. |
template <class C, class T, class L> int FindBinary(const C& v, const T& val, const L& less)
Finds position of element with specified value in the container sorted by less predicate. If no such element exists, a negative value is returned.
|
Return value |
Position in container. |
template <class C, class T> int FindBinary(const C& v, const T& val)
Finds position of element with specified value in the container sorted by operator< predicate. If no such element exists, a negative value is returned.
|
Return value |
Position in container. |
template <class C, class L> C& AppendSorted(C& dest, const C& src, const L& less)
Merges source NTL container to destination NTL container. Both containers must be sorted in ascending order. After the operation, destination container is sorted in ascending order and contains values from both containers. Duplicate values are preserved. Ordering predicate is determined by less.
|
dest |
Destination container. |
|
Return value |
Destination container.template<class C> |
template <class C> C& AppendSorted(C& dest, const C& src)
Merges source NTL container to destination NTL container. Both containers must be sorted in ascending order. After the operation, destination container is sorted in ascending order and contains values from both containers. Duplicate values are preserved. Ordering is determined by operator<.
|
dest |
Destination container. |
|
Return value |
Destination container.template<class C> |
template <class C, class L> C& UnionSorted(C& dest, const C& src, const L& less)
Merges source NTL container to destination NTL container. Both containers must be sorted in ascending order and values must be unique. After the operation, destination container is sorted in ascending order and contains unique values from both containers. Ordering is determined by less.
|
dest |
Destination container. |
|
Return value |
Destination container. |
template <class C> C& UnionSorted(C& dest, const C& src)
Merges the source NTL container to the destination NTL container. Both containers must be sorted in ascending order and values must be unique. After the operation, destination container is sorted in ascending order and contains unique values from both containers. Ordering is determined by operator<.
|
dest |
Destination container. |
|
Return value |
Destination container. |
template <class C, class L> C& RemoveSorted(C& from, const C& what, const L& less)
Removes elements of source container from destination container. Both containers must be sorted in ascending order and values must be unique. Ordering is determined by less.
|
from |
Destination container. |
|
Return value |
Destination container. |
template <class C> C& RemoveSorted(C& from, const C& what)
Removes elements of source container from destination container. Both containers must be sorted in ascending order and values must be unique. Ordering is determined by operator<.
|
from |
Destination container. |
|
Return value |
Destination container. |
template <class D, class S, class L> D& IntersectSorted(D& dest, const S& src, const L& less)
Removes elements from destination container that are not contained in source container. Both containers must be sorted in ascending order and values must be unique. Ordering is determined by less.
|
D |
Type of destination container. |
|
S |
Type of source container. |
|
dest |
Destination container. |
|
less |
Destination container. |
template <class D, class S> D& IntersectSorted(D& dest, const S& src)
Removes elements from destination container that are not contained in source container. Both containers must be sorted in ascending order and values must be unique. Ordering is determined by operator<.
|
D |
Type of destination container. |
|
S |
Type of source container. |
|
dest |
Destination container. |
|
Return value |
Destination container. |
template <class T, class Less> void Sort(T& c, const Less& less)
Sorts container. Ordering is determined by less.
IterSwap must be defined for T::Iterator.
template <class T> void Sort(T& c)
Sorts container. Ordering is determined by operator<.
IterSwap must be defined for T::Iterator.
template <class KC, class VC, class Less> void IndexSort(KC& keys, VC& values, const Less& less)
Sorts pair of containers. Both containers must have same number of items. Resulting order is determined by the keys container. Ordering is determined by less.
|
KC |
Type of keys container. |
|
values |
Container of values. |
template <class KC, class VC> void IndexSort(KC& keys, VC& values)
Sorts pair of containers. Both containers must have same number of items. Resulting order is determined by the keys container. Ordering is determined by operator<.
|
KC |
Type of keys container. |
|
VC |
Type of values container. |
|
values |
Container of values. |
template <class C, class Less> Vector<int> GetSortOrder(const C& container, const Less& less)
Creates ascending order of values in container. Ordering is determined by less.
|
container |
Source container. |
|
Return value |
Vector of positions of source container in sorted order. |
template <class C> Vector<int> GetSortOrder(const C& container)
Creates ascending order of values in container. Ordering is determined by operator<.
|
container |
Source container. |
|
Return value |
Vector of positions of source container in sorted order. |
template <class O, class T, class R> FieldRelationCls<O, T, R> FieldRelation(O (T::*member), const R& relation)
Creates ordering predicate for T based on the value of member variable of T.
|
member |
Member variable of T. |
|
relation |
Ordering relation for member. |
|
Return value |
Ordering predicate. |
template <class O, class T, class R> MethodRelationCls<O (T::*)(), T, R> MethodRelation(O (T::*method)(), const R& relation)
Creates ordering predicate for T based on the value returned by non-const method of T.
|
relation |
Ordering relation for value returned by method. |
|
Return value |
Ordering predicate. |
template <class O, class T, class R> MethodRelationCls<O (T::*)() const, T, R> MethodRelation(O (T::*method)() const, const R& relation)
Creates ordering predicate for T based on the value returned by const method of T.
|
relation |
Ordering relation for value returned by method. |
|
Return value |
Ordering predicate. |
|