Skip to content

Algorithms

disksing edited this page Dec 15, 2019 · 1 revision

Non-modifying sequence operations

Function Description
AllOf AnyOf NoneOf checks if a predicate is true for all, any or none of the elements in a range
ForEach applies a function to a range of elements
ForEachN applies a function object to the first n elements of a sequence
Count CountIf returns the number of elements satisfying specific criteria
Mismatch MismatchBy finds the first position where two ranges differ
Find FindIf FindIfNot finds the first element satisfying specific criteria
FindEnd FindEndBy finds the last sequence of elements in a certain range
FindFirstOf FindFirstOfBy searches for any one of a set of elements
AdjacentFind AdjacentFindBy finds the first two adjacent items that are equal (or satisfy a given predicate)
Search SearchBy searches for a range of elements
SearchN SearchNBy searches a range for a number of consecutive copies of an element

Modifying sequence operations

Function Description
Copy CopyIf copies a range of elements to a new location
CopyN copies a number of elements to a new location
CopyBackward copies a range of elements in backwards order
Fill copy-assigns the given value to every element in a range
FillN copy-assigns the given value to N elements in a range
Transform TransformBinary applies a function to a range of elements, storing results in a destination range
Generate assigns the results of successive function calls to every element in a range
GenerateN assigns the results of successive function calls to N elements in a range
Remove RemoveIf removes elements satisfying specific criteria
RemoveCopy RemoveCopyIf copies a range of elements omitting those that satisfy specific criteria
Replace ReplaceIf replaces all values satisfying specific criteria with another value
ReplaceCopy ReplaceCopyIf copies a range, replacing elements satisfying specific criteria with another value
Swap swaps the values of two iterators
SwapRanges swaps two ranges of elements
Reverse reverses the order of elements in a range
ReverseCopy creates a copy of a range that is reversed
Rotate rotates the order of elements in a range
RotateCopy copies and rotate a range of elements
Shuffle randomly re-orders elements in a range
Sample selects n random elements from a sequence
Unique UniqueIf removes consecutive duplicate elements in a range
UniqueCopy UniqueCopyIf creates a copy of some range of elements that contains no consecutive duplicates

Partitioning operations

Function Description
IsPartitioned determines if the range is partitioned by the given predicate
Partition divides a range of elements into two groups
PartitionCopy copies a range dividing the elements into two groups
StablePartition divides elements into two groups while preserving their relative order
PartitionPoint locates the partition point of a partitioned range

Sorting operations

Function Description
IsSorted IsSortedBy checks whether a range is sorted into ascending order
IsSortedUntil IsSortedUntilBy finds the largest sorted subrange
Sort SortBy sorts a range into ascending order
PartialSort PartialSortBy sorts the first N elements of a range
PartialSortCopy PartialSortCopyBy copies and partially sorts a range of elements
StableSort StableSortBy sorts a range of elements while preserving order between equal elements
NthElement NthElementBy partially sorts the given range making sure that it is partitioned by the given element

Binary search operations (on sorted ranges)

Function Description
LowerBound LowerBoundBy returns an iterator to the first element not less than the given value
UpperBound UpperBoundBy returns an iterator to the first element greater than a certain value
BinarySearch BinarySearchBy determines if an element exists in a certain range
EqualRange EqualRangeBy returns range of elements matching a specific key

Other operations on sorted ranges

Function Description
Merge MergeBy merges two sorted ranges
InplaceMerge InplaceMergeBy merges two ordered ranges in-place

Set operations (on sorted ranges)

Function Description
Includes IncludesBy returns true if one set is a subset of another
SetDifference SetDifferenceBy computes the difference between two sets
SetIntersection SetIntersectionBy computes the intersection of two sets
SetSymmetricDifference SetSymmetricDifferenceBy computes the symmetric difference between two sets
SetUnion SetUnionBy computes the union of two sets

Heap operations

Function Description
IsHeap IsHeapBy checks if the given range is a max heap
IsHeapUntil IsHeapUntilBy finds the largest subrange that is a max heap
MakeHeap MakeHeapBy creates a max heap out of a range of elements
PushHeap PushHeapBy adds an element to a max heap
PopHeap PopHeapBy removes the largest element from a max heap
SortHeap SortHeapBy turns a max heap into a range of elements sorted in ascending order

Minimum/maximum operations

Function Description
Max MaxBy returns the greater of the given values
MaxElement MaxElementBy returns the largest element in a range
Min MinBy returns the smaller of the given values
MinElement MinElementBy returns the smallest element in a range
Minmax MinmaxBy returns the smaller and larger of two elements
MinmaxElement MinmaxElementBy returns the smallest and the largest elements in a range
Clamp ClampBy clamps a value between a pair of boundary values

Comparison operations

Function Description
Equal EqualBy determines if two sets of elements are the same
LexicographicalCompare LexicographicalCompareBy returns true if one range is lexicographically less than another
LexicographicalCompareThreeWay LexicographicalCompareThreeWayBy compares two ranges using three-way comparison

Permutation operations

Function Description
IsPermutation IsPermutationBy determines if a sequence is a permutation of another sequence
NextPermutation NextPermutationBy generates the next greater lexicographic permutation of a range of elements
PrevPermutation PrevPermutationBy generates the next smaller lexicographic permutation of a range of elements

Numeric operations

Function Description
Iota IotaBy fills a range with successive increments of the starting value
Accumulate AccumulateBy sums up a range of elements
InnerProduct InnerProductBy computes the inner product of two ranges of elements
AdjacentDifference AdjacentDifferenceBy computes the differences between adjacent elements in a range
PartialSum PartialSumBy computes the partial sum of a range of elements
ExclusiveScan ExclusiveScanBy similar to PartialSum, excludes the ith input element from the ith sum
InclusiveScan InclusiveScanBy similar to PartialSum, includes the ith input element in the ith sum
TransformExclusiveScan TransformExclusiveScanBy applies a function, then calculates exclusive scan
TransformInclusiveScan TransformInclusiveScanBy applies a function, then calculates inclusive scan