algo

package
v2.0.0-...-1f204b1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accumulate

func Accumulate[T Numeric, It InputIter[T, It]](first, last It, v T) T

Accumulate computes the sum of the given value v and the elements in the range [first, last), using v+=x.

func AccumulateBy

func AccumulateBy[T1, T2 any, It InputIter[T1, It]](first, last It, v T2, add BinaryOperation[T2, T1, T2]) T2

AccumulateBy computes the sum of the given value v and the elements in the range [first, last), using v=add(v,x).

func AdjacentDifference

func AdjacentDifference[T Numeric, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out) Out

AdjacentDifference computes the differences between the second and the first of each adjacent pair of elements of the range [first, last) and writes them to the range beginning at dFirst + 1. An unmodified copy of first is written to dFirst. Differences are calculated by cur-prev.

func AdjacentDifferenceBy

func AdjacentDifferenceBy[T any, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, sub BinaryOperation[T, T, T]) Out

AdjacentDifferenceBy computes the differences between the second and the first of each adjacent pair of elements of the range [first, last) and writes them to the range beginning at dFirst + 1. An unmodified copy of first is written to dFirst. Differences are calculated by sub(cur,prev).

func AdjacentFind

func AdjacentFind[T comparable, It ForwardReader[T, It]](first, last It) It

AdjacentFind searches the range [first, last) for two consecutive identical elements.

func AdjacentFindBy

func AdjacentFindBy[T any, It ForwardReader[T, It]](first, last It, eq EqComparer[T, T]) It

AdjacentFindBy searches the range [first, last) for two consecutive identical elements.

Elements are compared using the given binary comparer eq.

func AllOf

func AllOf[T any, It InputIter[T, It]](first, last It, pred UnaryPredicate[T]) bool

AllOf checks if unary predicate pred returns true for all elements in the range [first, last).

func AnyOf

func AnyOf[T any, It InputIter[T, It]](first, last It, pred UnaryPredicate[T]) bool

AnyOf checks if unary predicate pred returns true for at least one element in the range [first, last).

func BinarySearch

func BinarySearch[T Ordered, It ForwardReader[T, It]](first, last It, v T) bool

BinarySearch checks if an element equivalent to value appears within the range [first, last).

func BinarySearchBy

func BinarySearchBy[T any, It ForwardReader[T, It]](first, last It, v T, less LessComparer[T]) bool

BinarySearchBy checks if an element equivalent to value appears within the range [first, last).

Elements are compared using the given binary comparer less.

func Clamp

func Clamp[T Ordered](v, lo, hi T) T

Clamp clamps a value between a pair of boundary values.

func ClampBy

func ClampBy[T any](v, lo, hi T, less LessComparer[T]) T

ClampBy clamps a value between a pair of boundary values.

Values are compared using the given binary comparer less.

func Copy

func Copy[T any, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out) Out

Copy copies the elements in the range, defined by [first, last), to another range beginning at dFirst.

It returns an iterator in the destination range, pointing past the last element copied.

func CopyBackward

func CopyBackward[T any, In BidiReader[T, In], Out BidiWriter[T, Out]](first, last In, dLast Out) Out

CopyBackward copies the elements from the range, defined by [first, last), to another range ending at dLast.

The elements are copied in reverse order (the last element is copied first), but their relative order is preserved. It returns an iterator to the last element copied.

func CopyIf

func CopyIf[T any, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, pred UnaryPredicate[T]) Out

CopyIf copies the elements in the range, defined by [first, last), and predicate pred returns true, to another range beginning at dFirst.

It returns an iterator in the destination range, pointing past the last element copied.

func CopyN

func CopyN[T any, In InputIter[T, In], Out OutputIter[T]](first In, count int, dFirst Out) Out

CopyN copies exactly count values from the range beginning at first to the range beginning at dFirst.

It returns an iterator in the destination range, pointing past the last element copied.

func Count

func Count[T comparable, It InputIter[T, It]](first, last It, v T) int

Count counts the elements that are equal to value.

func CountIf

func CountIf[T any, It InputIter[T, It]](first, last It, pred UnaryPredicate[T]) int

CountIf counts elements for which predicate pred returns true.

func Equal

func Equal[T comparable, In1 InputIter[T, In1], In2 InputIter[T, In2]](first1, last1 In1, first2 In2, last2 *In2) bool

Equal returns true if the range [first1, last1) is equal to the range [first2, last2), and false otherwise.

If last2 is nil, it denotes first2 + (last1 - first1).

func EqualBy

func EqualBy[T1, T2 any, In1 InputIter[T1, In1], In2 InputIter[T2, In2]](first1, last1 In1, first2 In2, last2 *In2, eq EqComparer[T1, T2]) bool

EqualBy returns true if the range [first1, last1) is equal to the range [first2, last2), and false otherwise.

If last2 is nil, it denotes first2 + (last1 - first1). Elements are compared using the given binary comparer eq.

func EqualRange

func EqualRange[T Ordered, It ForwardReader[T, It]](first, last It, v T) (It, It)

EqualRange returns a range containing all elements equivalent to value in the range [first, last).

func EqualRangeBy

func EqualRangeBy[T any, It ForwardReader[T, It]](first, last It, v T, less LessComparer[T]) (It, It)

EqualRangeBy returns a range containing all elements equivalent to value in the range [first, last).

Elements are compared using the given binary comparer less.

func ExclusiveScan

func ExclusiveScan[T Numeric, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, v T) Out

ExclusiveScan computes an exclusive prefix sum operation using v=v+cur for the range [first, last), using v as the initial value, and writes the results to the range beginning at dFirst. "exclusive" means that the i-th input element is not included in the i-th sum.

func ExclusiveScanBy

func ExclusiveScanBy[T1, T2 any, In InputIter[T1, In], Out OutputIter[T2]](first, last In, dFirst Out, v T2, add BinaryOperation[T2, T1, T2]) Out

ExclusiveScanBy computes an exclusive prefix sum operation using v=add(v,cur) for the range [first, last), using v as the initial value, and writes the results to the range beginning at dFirst. "exclusive" means that the i-th input element is not included in the i-th sum.

func Fill

func Fill[T any, It ForwardWriter[T, It]](first, last It, v T)

Fill assigns the given value to the elements in the range [first, last).

func FillN

func FillN[T any, Out OutputIter[T]](dFirst Out, count int, v T)

FillN assigns the given value to the first count elements in the range beginning at dFirst.

If count <= 0, it does nothing.

func Find

func Find[T comparable, It InputIter[T, It]](first, last It, v T) It

Find returns the first element in the range [first, last) that is equal to value.

func FindEnd

func FindEnd[T comparable, It ForwardReader[T, It]](first, last, sFirst, sLast It) It

FindEnd searches for the last occurrence of the sequence [sFirst, sLast) in the range [first, last).

If [sFirst, sLast) is empty or such sequence is found, last is returned.

func FindEndBy

func FindEndBy[T1, T2 any, It1 ForwardReader[T1, It1], It2 ForwardReader[T2, It2]](first, last It1, sFirst, sLast It2, eq EqComparer[T1, T2]) It1

FindEndBy searches for the last occurrence of the sequence [sFirst, sLast) in the range [first, last).

If [sFirst, sLast) is empty or such sequence is found, last is returned. Elements are compared using the given binary comparer eq.

func FindFirstOf

func FindFirstOf[T comparable, It ForwardReader[T, It]](first, last It, sFirst, sLast It) It

FindFirstOf searches the range [first, last) for any of the elements in the range [sFirst, sLast).

func FindFirstOfBy

func FindFirstOfBy[T1, T2 any, It1 ForwardReader[T1, It1], It2 ForwardReader[T2, It2]](first, last It1, sFirst, sLast It2, eq EqComparer[T1, T2]) It1

FindFirstOfBy searches the range [first, last) for any of the elements in the range [sFirst, sLast).

Elements are compared using the given binary comparer eq.

func FindIf

func FindIf[T any, It InputIter[T, It]](first, last It, pred UnaryPredicate[T]) It

FindIf returns the first element in the range [first, last) which predicate pred returns true.

func FindIfNot

func FindIfNot[T any, It InputIter[T, It]](first, last It, pred UnaryPredicate[T]) It

FindIfNot returns the first element in the range [first, last) which predicate pred returns false.

func Generate

func Generate[T any, It ForwardWriter[T, It]](first, last It, g Generator[T])

Generate assigns each element in range [first, last) a value generated by the given function object g.

func GenerateN

func GenerateN[T any, It OutputIter[T]](dFirst It, count int, g Generator[T]) It

GenerateN assigns values, generated by given function object g, to the first count elements in the range beginning at dFirst.

If count <= 0, it does nothing.

func Includes

func Includes[T Ordered, It1 InputIter[T, It1], It2 InputIter[T, It2]](first1, last1 It1, first2, last2 It2) bool

Includes returns true if the sorted range [first2, last2) is a subsequence of the sorted range [first1, last1). (A subsequence need not be contiguous.)

func IncludesBy

func IncludesBy[T any, It1 InputIter[T, It1], It2 InputIter[T, It2]](first1, last1 It1, first2, last2 It2, less LessComparer[T]) bool

IncludesBy returns true if the sorted range [first2, last2) is a subsequence of the sorted range [first1, last1). (A subsequence need not be contiguous.)

Elements are compared using the given binary comparer less.

func InclusiveScan

func InclusiveScan[T Numeric, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, v T) Out

InclusiveScan computes an inclusive prefix sum operation using v=v+cur for the range [first, last), using v as the initial value (if provided), and writes the results to the range beginning at dFirst. "inclusive" means that the i-th input element is included in the i-th sum.

func InclusiveScanBy

func InclusiveScanBy[T1, T2 any, In InputIter[T1, In], Out OutputIter[T2]](first, last In, dFirst Out, v T2, add BinaryOperation[T2, T1, T2]) Out

InclusiveScanBy computes an inclusive prefix sum operation using v=add(v,cur) for the range [first, last), using v as the initial value (if provided), and writes the results to the range beginning at dFirst. "inclusive" means that the i-th input element is included in the i-th sum.

func InnerProduct

func InnerProduct[T Numeric, It1 InputIter[T, It1], It2 InputIter[T, It2]](first1, last1 It1, first2 It2, v T) T

InnerProduct computes inner product (i.e. sum of products) or performs ordered map/reduce operation on the range [first1, last1), using v=v+x*y.

func InnerProductBy

func InnerProductBy[T1, T2, T3, T4 any, It1 InputIter[T1, It1], It2 InputIter[T2, It2]](first1, last1 It1, first2 It2, v T4, add BinaryOperation[T4, T3, T4], mul BinaryOperation[T1, T2, T3]) T4

InnerProductBy computes inner product (i.e. sum of products) or performs ordered map/reduce operation on the range [first1, last1), using v=add(v,mul(x,y)).

func InplaceMerge

func InplaceMerge[T Ordered, It BidiReadWriter[T, It]](first, middle, last It)

InplaceMerge Merges two consecutive sorted ranges [first, middle) and [middle, last) into one sorted range [first, last). For equivalent elements in the original two ranges, the elements from the first range (preserving their original order) precede the elements from the second range (preserving their original order).

func InplaceMergeBy

func InplaceMergeBy[T any, It BidiReadWriter[T, It]](first, middle, last It, less LessComparer[T])

InplaceMergeBy Merges two consecutive sorted ranges [first, middle) and [middle, last) into one sorted range [first, last). For equivalent elements in the original two ranges, the elements from the first range (preserving their original order) precede the elements from the second range (preserving their original order).

Elements are compared using the given binary comparer less.

func Iota

func Iota[T Integer, It ForwardWriter[T, It]](first, last It, v T)

Iota fills the range [first, last) with sequentially increasing values, starting with v and repetitively evaluating v++.

func IotaBy

func IotaBy[T any, It ForwardWriter[T, It]](first, last It, v T, inc UnaryOperation[T, T])

IotaBy fills the range [first, last) with sequentially increasing values, starting with v and repetitively evaluating inc(v).

func IsHeap

func IsHeap[T Ordered, It RandomReader[T, It]](first, last It) bool

IsHeap checks if the elements in range [first, last) are a max heap.

func IsHeapBy

func IsHeapBy[T any, It RandomReader[T, It]](first, last It, less LessComparer[T]) bool

IsHeapBy checks if the elements in range [first, last) are a max heap.

Elements are compared using the given binary comparer less.

func IsHeapUntil

func IsHeapUntil[T Ordered, It RandomReader[T, It]](first, last It) It

IsHeapUntil examines the range [first, last) and finds the largest range beginning at first which is a max heap.

func IsHeapUntilBy

func IsHeapUntilBy[T any, It RandomReader[T, It]](first, last It, less LessComparer[T]) It

IsHeapUntilBy examines the range [first, last) and finds the largest range beginning at first which is a max heap.

Elements are compared using the given binary comparer less.

func IsPartitioned

func IsPartitioned[T any, It InputIter[T, It]](first, last It, pred UnaryPredicate[T]) bool

IsPartitioned returns true if all elements in the range [first, last) that satisfy the predicate pred appear before all elements that don't. Also returns true if [first, last) is empty.

func IsPermutation

func IsPermutation[T comparable, It1 ForwardReader[T, It1], It2 ForwardReader[T, It2]](first1, last1 It1, first2 It2, last2 *It2) bool

IsPermutation returns true if there exists a permutation of the elements in the range [first1, last1) that makes that range equal to the range [first2,last2), where last2 denotes first2 + (last1 - first1) if it was not given.

func IsPermutationBy

func IsPermutationBy[T any, It1 ForwardReader[T, It1], It2 ForwardReader[T, It2]](first1, last1 It1, first2 It2, last2 *It2, eq EqComparer[T, T]) bool

IsPermutationBy returns true if there exists a permutation of the elements in the range [first1, last1) that makes that range equal to the range [first2,last2), where last2 denotes first2 + (last1 - first1) if it was not given.

Elements are compared using the given binary comparer eq.

func IsSorted

func IsSorted[T Ordered, It ForwardReader[T, It]](first, last It) bool

IsSorted checks if the elements in range [first, last) are sorted in non-descending order.

func IsSortedBy

func IsSortedBy[T any, It ForwardReader[T, It]](first, last It, less LessComparer[T]) bool

IsSortedBy checks if the elements in range [first, last) are sorted in non-descending order.

Elements are compared using the given binary comparer less.

func IsSortedUntil

func IsSortedUntil[T Ordered, It ForwardReader[T, It]](first, last It) It

IsSortedUntil examines the range [first, last) and finds the largest range beginning at first in which the elements are sorted in ascending order.

func IsSortedUntilBy

func IsSortedUntilBy[T any, It ForwardReader[T, It]](first, last It, less LessComparer[T]) It

IsSortedUntilBy examines the range [first, last) and finds the largest range beginning at first in which the elements are sorted in ascending order.

Elements are compared using the given binary comparer less.

func LexicographicalCompare

func LexicographicalCompare[T Ordered, In1 InputIter[T, In1], In2 InputIter[T, In2]](first1, last1 In1, first2, last2 In2) bool

LexicographicalCompare checks if the first range [first1, last1) is lexicographically less than the second range [first2, last2).

func LexicographicalCompareBy

func LexicographicalCompareBy[T any, In1 InputIter[T, In1], In2 InputIter[T, In2]](first1, last1 In1, first2, last2 In2, less LessComparer[T]) bool

LexicographicalCompareBy checks if the first range [first1, last1) is lexicographically less than the second range [first2, last2).

Elements are compared using the given binary comparer less.

func LexicographicalCompareThreeWay

func LexicographicalCompareThreeWay[T Ordered, In1 InputIter[T, In1], In2 InputIter[T, In2]](first1, last1 In1, first2, last2 In2) int

LexicographicalCompareThreeWay lexicographically compares two ranges [first1, last1) and [first2, last2) using three-way comparison. The result will be 0 if [first1, last1) == [first2, last2), -1 if [first1, last1) < [first2, last2), 1 if [first1, last1) > [first2, last2).

func LexicographicalCompareThreeWayBy

func LexicographicalCompareThreeWayBy[T1, T2 any, In1 InputIter[T1, In1], In2 InputIter[T2, In2]](first1, last1 In1, first2, last2 In2, cmp ThreeWayComparer[T1, T2]) int

LexicographicalCompareThreeWayBy lexicographically compares two ranges [first1, last1) and [first2, last2) using three-way comparison. The result will be 0 if [first1, last1) == [first2, last2), -1 if [first1, last1) < [first2, last2), 1 if [first1, last1) > [first2, last2).

Elements are compared using the given binary predicate cmp.

func LowerBound

func LowerBound[T Ordered, It ForwardReader[T, It]](first, last It, v T) It

LowerBound returns an iterator pointing to the first element in the range [first, last) that is not less than (i.e. greater or equal to) value, or last if no such element is found.

func LowerBoundBy

func LowerBoundBy[T any, It ForwardReader[T, It]](first, last It, v T, less LessComparer[T]) It

LowerBoundBy returns an iterator pointing to the first element in the range [first, last) that is not less than (i.e. greater or equal to) value, or last if no such element is found.

Elements are compared using the given binary comparer less.

func MakeHeap

func MakeHeap[T Ordered, It RandomReadWriter[T, It]](first, last It)

MakeHeap constructs a max heap in the range [first, last).

func MakeHeapBy

func MakeHeapBy[T any, It RandomReadWriter[T, It]](first, last It, less LessComparer[T])

MakeHeapBy constructs a max heap in the range [first, last).

Elements are compared using the given binary comparer less.

func Max

func Max[T Ordered](a, b T) T

Max returns the greater of the given values.

func MaxBy

func MaxBy[T any](a, b T, less LessComparer[T]) T

MaxBy returns the greater of the given values.

Values are compared using the given binary comparer less.

func MaxElement

func MaxElement[T Ordered, It ForwardReader[T, It]](first, last It) It

MaxElement returns the largest element in a range.

func MaxElementBy

func MaxElementBy[T any, It ForwardReader[T, It]](first, last It, less LessComparer[T]) It

MaxElementBy returns the largest element in a range.

Values are compared using the given binary comparer less.

func Merge

func Merge[T Ordered, In1 InputIter[T, In1], In2 InputIter[T, In2], Out OutputIter[T]](first1, last1 In1, first2, last2 In2, dFirst Out) Out

Merge merges two sorted ranges [first1, last1) and [first2, last2) into one sorted range beginning at dFirst.

func MergeBy

func MergeBy[T any, In1 InputIter[T, In1], In2 InputIter[T, In2], Out OutputIter[T]](first1, last1 In1, first2, last2 In2, dFirst Out, less LessComparer[T]) Out

MergeBy merges two sorted ranges [first1, last1) and [first2, last2) into one sorted range beginning at dFirst.

Elements are compared using the given binary comparer less.

func Min

func Min[T Ordered](a, b T) T

Min returns the smaller of the given values.

func MinBy

func MinBy[T any](a, b T, less LessComparer[T]) T

MinBy returns the smaller of the given values.

Values are compared using the given binary comparer less.

func MinElement

func MinElement[T Ordered, It ForwardReader[T, It]](first, last It) It

MinElement returns the smallest element in a range.

func MinElementBy

func MinElementBy[T any, It ForwardReader[T, It]](first, last It, less LessComparer[T]) It

MinElementBy returns the smallest element in a range.

Values are compared using the given binary comparer less.

func Minmax

func Minmax[T Ordered](a, b T) (T, T)

Minmax returns the smaller and larger of two elements.

func MinmaxBy

func MinmaxBy[T any](a, b T, less LessComparer[T]) (T, T)

MinmaxBy returns the smaller and larger of two elements.

Values are compared using the given binary comparer less.

func MinmaxElement

func MinmaxElement[T Ordered, It ForwardReader[T, It]](first, last It) (It, It)

MinmaxElement returns the smallest and the largest elements in a range.

func MinmaxElementBy

func MinmaxElementBy[T any, It ForwardReader[T, It]](first, last It, less LessComparer[T]) (It, It)

MinmaxElementBy returns the smallest and the largest elements in a range.

Values are compared using the given binary comparer less.

func Mismatch

func Mismatch[T comparable, It1 InputIter[T, It1], It2 InputIter[T, It2]](first1, last1 It1, first2 It2, last2 *It2) (It1, It2)

Mismatch returns the first mismatching pair of elements from two ranges: one defined by [first1, last1) and another defined by [first2, last2).

If last2 is nil, it denotes first2 + (last1 - first1).

func MismatchBy

func MismatchBy[T1, T2 any, It1 InputIter[T1, It1], It2 InputIter[T2, It2]](first1, last1 It1, first2 It2, last2 *It2, eq EqComparer[T1, T2]) (It1, It2)

MismatchBy returns the first mismatching pair of elements from two ranges: one defined by [first1, last1) and another defined by [first2, last2).

If last2 is nil, it denotes first2 + (last1 - first1). Elements are compared using the given comparer eq.

func NextPermutation

func NextPermutation[T Ordered, It BidiReadWriter[T, It]](first, last It) bool

NextPermutation transforms the range [first, last) into the next permutation from the set of all permutations that are lexicographically ordered. Returns true if such permutation exists, otherwise transforms the range into the first permutation (as if by Sort(first, last)) and returns false.

func NextPermutationBy

func NextPermutationBy[T any, It BidiReadWriter[T, It]](first, last It, less LessComparer[T]) bool

NextPermutationBy transforms the range [first, last) into the next permutation from the set of all permutations that are lexicographically ordered with respect to less. Returns true if such permutation exists, otherwise transforms the range into the first permutation (as if by Sort(first, last)) and returns false.

Elements are compared using the given binary comparer less.

func NoneOf

func NoneOf[T any, It InputIter[T, It]](first, last It, pred UnaryPredicate[T]) bool

NoneOf checks if unary predicate pred returns true for no elements in the range [first, last).

func NthElement

func NthElement[T Ordered, It RandomReadWriter[T, It]](first, nth, last It)

NthElement is a partial sorting algorithm that rearranges elements in [first, last) such that: a. The element pointed at by nth is changed to whatever element would occur in that position if [first, last) were sorted. b. All of the elements before this new nth element are less than or equal to the elements after the new nth element.

func NthElementBy

func NthElementBy[T any, It RandomReadWriter[T, It]](first, nth, last It, less LessComparer[T])

NthElementBy is a partial sorting algorithm that rearranges elements in [first, last) such that: a. The element pointed at by nth is changed to whatever element would occur in that position if [first, last) were sorted. b. All of the elements before this new nth element are less than or equal to the elements after the new nth element.

Elements are compared using the given binary comparer less.

func PartialSort

func PartialSort[T Ordered, It RandomReadWriter[T, It]](first, middle, last It)

PartialSort rearranges elements such that the range [first, middle) contains the sorted (middle-first) smallest elements in the range [first, last).

The order of equal elements is not guaranteed to be preserved. The order of the remaining elements in the range [middle, last) is unspecified.

func PartialSortBy

func PartialSortBy[T any, It RandomReadWriter[T, It]](first, middle, last It, less LessComparer[T])

PartialSortBy rearranges elements such that the range [first, middle) contains the sorted (middle-first) smallest elements in the range [first, last).

The order of equal elements is not guaranteed to be preserved. The order of the remaining elements in the range [middle, last) is unspecified. Elements are compared using the given binary comparer less.

func PartialSortCopy

func PartialSortCopy[T Ordered, In InputIter[T, In], Out RandomReadWriter[T, Out]](first, last In, dFirst, dLast Out)

PartialSortCopy sorts some of the elements in the range [first, last) in ascending order, storing the result in the range [dFirst, dLast).

At most dLast - dFirst of the elements are placed sorted to the range [dFirst, dFirst + n). n is the number of elements to sort (n = min(last - first, dLast - dFirst)). The order of equal elements is not guaranteed to be preserved.

func PartialSortCopyBy

func PartialSortCopyBy[T any, In InputIter[T, In], Out RandomReadWriter[T, Out]](first, last In, dFirst, dLast Out, less LessComparer[T])

PartialSortCopyBy sorts some of the elements in the range [first, last) in ascending order, storing the result in the range [dFirst, dLast).

At most dLast - dFirst of the elements are placed sorted to the range [dFirst, dFirst + n). n is the number of elements to sort (n = min(last - first, dLast - dFirst)). The order of equal elements is not guaranteed to be preserved. Elements are compared using the given binary comparer less.

func PartialSum

func PartialSum[T Numeric, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out) Out

PartialSum computes the partial sums of the elements in the subranges of the range [first, last) and writes them to the range beginning at dFirst. Sums are calculated by sum=sum+cur.

func PartialSumBy

func PartialSumBy[T any, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, add BinaryOperation[T, T, T]) Out

PartialSumBy computes the partial sums of the elements in the subranges of the range [first, last) and writes them to the range beginning at dFirst. Sums are calculated by sum=add(sum,cur).

func Partition

func Partition[T any, It ForwardReadWriter[T, It]](first, last It, pred UnaryPredicate[T]) It

Partition reorders the elements in the range [first, last) in such a way that all elements for which the predicate pred returns true precede the elements for which predicate pred returns false.

Relative order of the elements is not preserved.

func PartitionCopy

func PartitionCopy[T any, In InputIter[T, In], Out OutputIter[T]](first, last In, outTrue, outFalse Out, pred UnaryPredicate[T]) (Out, Out)

PartitionCopy copies the elements from the range [first, last) to two different ranges depending on the value returned by the predicate pred. The elements that satisfy the predicate pred are copied to the range beginning at outTrue. The rest of the elements are copied to the range beginning at outFalse.

func PartitionPoint

func PartitionPoint[T any, It ForwardReader[T, It]](first, last It, pred UnaryPredicate[T]) It

PartitionPoint examines the partitioned (as if by Partition) range [first, last) and locates the end of the first partition, that is, the first element that does not satisfy pred or last if all elements satisfy pred.

func PopHeap

func PopHeap[T Ordered, It RandomReadWriter[T, It]](first, last It)

PopHeap swaps the value in the position first and the value in the position last-1 and makes the subrange [first, last-1) into a heap. This has the effect of removing the first element from the heap defined by the range [first, last).

func PopHeapBy

func PopHeapBy[T any, It RandomReadWriter[T, It]](first, last It, less LessComparer[T])

PopHeapBy swaps the value in the position first and the value in the position last-1 and makes the subrange [first, last-1) into a heap. This has the effect of removing the first element from the heap defined by the range [first, last).

Elements are compared using the given binary comparer less.

func PrevPermutation

func PrevPermutation[T Ordered, It BidiReadWriter[T, It]](first, last It) bool

PrevPermutation transforms the range [first, last) into the previous permutation from the set of all permutations that are lexicographically ordered. Returns true if such permutation exists, otherwise transforms the range into the last permutation (as if by Sort(first, last); Reverse(first, last);) and returns false.

func PrevPermutationBy

func PrevPermutationBy[T any, It BidiReadWriter[T, It]](first, last It, less LessComparer[T]) bool

PrevPermutationBy transforms the range [first, last) into the previous permutation from the set of all permutations that are lexicographically ordered with respect to less. Returns true if such permutation exists, otherwise transforms the range into the last permutation (as if by Sort(first, last); Reverse(first, last);) and returns false.

Elements are compared using the given binary comparer less.

func PushHeap

func PushHeap[T Ordered, It RandomReadWriter[T, It]](first, last It)

PushHeap inserts the element at the position last-1 into the max heap defined by the range [first, last-1).

func PushHeapBy

func PushHeapBy[T any, It RandomReadWriter[T, It]](first, last It, less LessComparer[T])

PushHeapBy inserts the element at the position last-1 into the max heap defined by the range [first, last-1).

Elements are compared using the given binary comparer less.

func Remove

func Remove[T comparable, It ForwardReadWriter[T, It]](first, last It, v T) It

Remove removes all elements equal to v from the range [first, last) and returns a past-the-end iterator for the new end of the range.

func RemoveCopy

func RemoveCopy[T comparable, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, v T) Out

RemoveCopy copies elements from the range [first, last), to another range beginning at dFirst, omitting the elements equal to v.

Source and destination ranges cannot overlap.

func RemoveCopyIf

func RemoveCopyIf[T any, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, pred UnaryPredicate[T]) Out

RemoveCopyIf copies elements from the range [first, last), to another range beginning at dFirst, omitting the elements which predicate function returns true.

Source and destination ranges cannot overlap.

func RemoveIf

func RemoveIf[T any, It ForwardReadWriter[T, It]](first, last It, pred UnaryPredicate[T]) It

RemoveIf removes all elements which predicate function returns true from the range [first, last) and returns a past-the-end iterator for the new end of the range.

func Replace

func Replace[T comparable, It ForwardReadWriter[T, It]](first, last It, old, new T)

Replace replaces all elements equal to old with new in the range [first, last).

func ReplaceCopy

func ReplaceCopy[T comparable, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, old, new T) Out

ReplaceCopy copies the elements from the range [first, last) to another range beginning at dFirst replacing all elements equal to old with new.

The source and destination ranges cannot overlap.

func ReplaceCopyIf

func ReplaceCopyIf[T any, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, pred UnaryPredicate[T], v T) Out

ReplaceCopyIf copies the elements from the range [first, last) to another range beginning at dFirst replacing all elements satisfy pred with new.

The source and destination ranges cannot overlap.

func ReplaceIf

func ReplaceIf[T any, It ForwardReadWriter[T, It]](first, last It, pred UnaryPredicate[T], v T)

ReplaceIf replaces all elements satisfy pred with new in the range [first, last).

func Reverse

func Reverse[T any, It BidiReadWriter[T, It]](first, last It)

Reverse reverses the order of the elements in the range [first, last).

func ReverseCopy

func ReverseCopy[T any, In BidiReader[T, In], Out OutputIter[T]](first, last In, dFirst Out) Out

ReverseCopy copies the elements from the range [first, last) to another range beginning at dFirst in such a way that the elements in the new range are in reverse order.

func Rotate

func Rotate[T any, It ForwardReadWriter[T, It]](first, nFirst, last It) It

Rotate performs a left rotation on a range of elements in such a way, that the element nFirst becomes the first element of the new range and nFirst - 1 becomes the last element.

func RotateCopy

func RotateCopy[T any, In ForwardReader[T, In], Out OutputIter[T]](first, nFirst, last In, dFirst Out) Out

RotateCopy copies the elements from the range [first, last), to another range beginning at dFirst in such a way, that the element nFirst becomes the first element of the new range and nFirst - 1 becomes the last element.

func Sample

func Sample[T any, In ForwardReader[T, In], Out OutputIter[T]](first, last In, out Out, n int, r *rand.Rand) Out

Sample selects n elements from the sequence [first; last) such that each possible sample has equal probability of appearance, and writes those selected elements into the output iterator out.

func Search[T comparable, It ForwardReader[T, It]](first, last, sFirst, sLast It) It

Search searches for the first occurrence of the sequence of elements [sFirst, sLast) in the range [first, last).

func SearchBy

func SearchBy[T1, T2 any, It1 ForwardReader[T1, It1], It2 ForwardReader[T2, It2]](first, last It1, sFirst, sLast It2, eq EqComparer[T1, T2]) It1

SearchBy searches for the first occurrence of the sequence of elements [sFirst, sLast) in the range [first, last).

Elements are compared using the given binary comparer eq.

func SearchN

func SearchN[T comparable, It ForwardReader[T, It]](first, last It, count int, v T) It

SearchN searches the range [first, last) for the first sequence of count identical elements, each equal to the given value.

func SearchNBy

func SearchNBy[T1, T2 any, It ForwardReader[T1, It]](first, last It, count int, v T2, eq EqComparer[T1, T2]) It

SearchNBy searches the range [first, last) for the first sequence of count identical elements.

Elements are compared using the given binary comparer eq.

func SetDifference

func SetDifference[T Ordered, In1 InputIter[T, In1], In2 InputIter[T, In2], Out OutputIter[T]](first1, last1 In1, first2, last2 In2, dFirst Out) Out

SetDifference copies the elements from the sorted range [first1, last1) which are not found in the sorted range [first2, last2) to the range beginning at dFirst.

func SetDifferenceBy

func SetDifferenceBy[T any, In1 InputIter[T, In1], In2 InputIter[T, In2], Out OutputIter[T]](first1, last1 In1, first2, last2 In2, dFirst Out, less LessComparer[T]) Out

SetDifferenceBy copies the elements from the sorted range [first1, last1) which are not found in the sorted range [first2, last2) to the range beginning at dFirst.

Elements are compared using the given binary comparer less.

func SetIntersection

func SetIntersection[T Ordered, In1 InputIter[T, In1], In2 InputIter[T, In2], Out OutputIter[T]](first1, last1 In1, first2, last2 In2, dFirst Out) Out

SetIntersection constructs a sorted range beginning at dFirst consisting of elements that are found in both sorted ranges [first1, last1) and [first2, last2). If some element is found m times in [first1, last1) and n times in [first2, last2), the first Min(m, n) elements will be copied from the first range to the destination range.

The order of equivalent elements is preserved. The resulting range cannot overlap with either of the input ranges.

func SetIntersectionBy

func SetIntersectionBy[T any, In1 InputIter[T, In1], In2 InputIter[T, In2], Out OutputIter[T]](first1, last1 In1, first2, last2 In2, dFirst Out, less LessComparer[T]) Out

SetIntersectionBy constructs a sorted range beginning at dFirst consisting of elements that are found in both sorted ranges [first1, last1) and [first2, last2). If some element is found m times in [first1, last1) and n times in [first2, last2), the first Min(m, n) elements will be copied from the first range to the destination range.

The order of equivalent elements is preserved. The resulting range cannot overlap with either of the input ranges. Elements are compared using the given binary comparer less.

func SetSymmetricDifference

func SetSymmetricDifference[T Ordered, In1 InputIter[T, In1], Out OutputIter[T]](first1, last1 In1, first2, last2 In1, dFirst Out) Out

SetSymmetricDifference computes symmetric difference of two sorted ranges: the elements that are found in either of the ranges, but not in both of them are copied to the range beginning at dFirst. The resulting range is also sorted.

If some element is found m times in [first1, last1) and n times in [first2, last2), it will be copied to dFirst exactly Abs(m-n) times. If m>n, then the last m-n of those elements are copied from [first1,last1), otherwise the last n-m elements are copied from [first2,last2). The resulting range cannot overlap with either of the input ranges.

func SetSymmetricDifferenceBy

func SetSymmetricDifferenceBy[T any, In1 InputIter[T, In1], In2 InputIter[T, In2], Out OutputIter[T]](first1, last1 In1, first2, last2 In2, dFirst Out, less LessComparer[T]) Out

SetSymmetricDifferenceBy computes symmetric difference of two sorted ranges: the elements that are found in either of the ranges, but not in both of them are copied to the range beginning at dFirst. The resulting range is also sorted.

If some element is found m times in [first1, last1) and n times in [first2, last2), it will be copied to dFirst exactly Abs(m-n) times. If m>n, then the last m-n of those elements are copied from [first1,last1), otherwise the last n-m elements are copied from [first2,last2). The resulting range cannot overlap with either of the input ranges. Elements are compared using the given binary comparer less.

func SetUnion

func SetUnion[T Ordered, In1 InputIter[T, In1], In2 InputIter[T, In2], Out OutputIter[T]](first1, last1 In1, first2, last2 In2, dFirst Out) Out

SetUnion constructs a sorted union beginning at dFirst consisting of the set of elements present in one or both sorted ranges [first1, last1) and [first2, last2).

If some element is found m times in [first1, last1) and n times in [first2, last2), then all m elements will be copied from [first1, last1) to dFirst, preserving order, and then exactly Max(n-m, 0) elements will be copied from [first2, last2) to dFirst, also preserving order.

func SetUnionBy

func SetUnionBy[T any, In1 InputIter[T, In1], In2 InputIter[T, In2], Out OutputIter[T]](first1, last1 In1, first2, last2 In2, dFirst Out, less LessComparer[T]) Out

SetUnionBy constructs a sorted union beginning at dFirst consisting of the set of elements present in one or both sorted ranges [first1, last1) and [first2, last2).

If some element is found m times in [first1, last1) and n times in [first2, last2), then all m elements will be copied from [first1, last1) to dFirst, preserving order, and then exactly Max(n-m, 0) elements will be copied from [first2, last2) to dFirst, also preserving order. Elements are compared using the given binary comparer less.

func Shuffle

func Shuffle[T any, It RandomReadWriter[T, It]](first, last It, r *rand.Rand)

Shuffle reorders the elements in the given range [first, last) such that each possible permutation of those elements has equal probability of appearance.

func Sort

func Sort[T Ordered, It RandomReadWriter[T, It]](first, last It)

Sort sorts the elements in the range [first, last) in ascending order. The order of equal elements is not guaranteed to be preserved.

func SortBy

func SortBy[T any, It RandomReadWriter[T, It]](first, last It, less LessComparer[T])

SortBy sorts the elements in the range [first, last) in ascending order. The order of equal elements is not guaranteed to be preserved.

Elements are compared using the given binary comparer less.

func SortHeap

func SortHeap[T Ordered, It RandomReadWriter[T, It]](first, last It)

SortHeap converts the max heap [first, last) into a sorted range in ascending order. The resulting range no longer has the heap property.

func SortHeapBy

func SortHeapBy[T any, It RandomReadWriter[T, It]](first, last It, less LessComparer[T])

SortHeapBy converts the max heap [first, last) into a sorted range in ascending order. The resulting range no longer has the heap property.

Elements are compared using the given binary comparer less.

func StablePartition

func StablePartition[T any, It ForwardReadWriter[T, It]](first, last It, pred UnaryPredicate[T]) It

StablePartition reorders the elements in the range [first, last) in such a way that all elements for which the predicate pred returns true precede the elements for which predicate pred returns false. Relative order of the elements is preserved.

func StablePartitionBidi

func StablePartitionBidi[T any, It BidiReadWriter[T, It]](first, last It, pred UnaryPredicate[T]) It

StablePartitionBidi reorders the elements in the range [first, last) in such a way that all elements for which the predicate pred returns true precede the elements for which predicate pred returns false. Relative order of the elements is preserved.

func StableSort

func StableSort[T Ordered, It RandomReadWriter[T, It]](first, last It)

StableSort sorts the elements in the range [first, last) in ascending order. The order of equivalent elements is guaranteed to be preserved.

func StableSortBy

func StableSortBy[T any, It RandomReadWriter[T, It]](first, last It, less LessComparer[T])

StableSortBy sorts the elements in the range [first, last) in ascending order.

The order of equivalent elements is guaranteed to be preserved. Elements are compared using the given binary comparer less.

func Swap

func Swap[T any](a, b ReadWriter[T])

Swap swaps value of two iterators.

func SwapRanges

func SwapRanges[T any, It1 ForwardReadWriter[T, It1], It2 ForwardReadWriter[T, It2]](first1, last1 It1, first2 It2)

SwapRanges exchanges elements between range [first1, last1) and another range starting at first2.

func Transform

func Transform[T1, T2 any, In InputIter[T1, In], Out OutputIter[T2]](first, last In, dFirst Out, op UnaryOperation[T1, T2]) Out

Transform applies the given function to the range [first, last) and stores the result in another range, beginning at dFirst.

func TransformBinary

func TransformBinary[T1, T2, T3 any, In1 ForwardReader[T1, In1], In2 ForwardReader[T2, In2], Out OutputIter[T3]](first1, last1 In1, first2 In2, dFirst Out, op BinaryOperation[T1, T2, T3]) Out

TransformBinary applies the given function to the two ranges [first, last), [first2, first2+last-first) and stores the result in another range, beginning at dFirst.

func TransformExclusiveScan

func TransformExclusiveScan[T1, T2 Numeric, In InputIter[T1, In], Out OutputIter[T2]](first, last In, dFirst Out, v T2, op UnaryOperation[T1, T2]) Out

TransformExclusiveScan transforms each element in the range [first, last) with op, then computes an exclusive prefix sum operation using v=v+cur for the range [first, last), using v as the initial value, and writes the results to the range beginning at dFirst. "exclusive" means that the i-th input element is not included in the i-th sum.

func TransformExclusiveScanBy

func TransformExclusiveScanBy[T1, T2, T3 any, In InputIter[T1, In], Out OutputIter[T3]](first, last In, dFirst Out, v T3, add BinaryOperation[T3, T2, T3], op UnaryOperation[T1, T2]) Out

TransformExclusiveScanBy transforms each element in the range [first, last) with op, then computes an exclusive prefix sum operation using v=add(v,cur) for the range [first, last), using v as the initial value, and writes the results to the range beginning at dFirst. "exclusive" means that the i-th input element is not included in the i-th sum.

func TransformInclusiveScan

func TransformInclusiveScan[T1, T2 Numeric, In InputIter[T1, In], Out OutputIter[T2]](first, last In, dFirst Out, v T2, op UnaryOperation[T1, T2]) Out

TransformInclusiveScan transforms each element in the range [first, last) with op, then computes an inclusive prefix sum operation using v=v+cur for the range [first, last), using v as the initial value (if provided), and writes the results to the range beginning at dFirst. "inclusive" means that the i-th input element is included in the i-th sum.

func TransformInclusiveScanBy

func TransformInclusiveScanBy[T1, T2, T3 any, In InputIter[T1, In], Out OutputIter[T3]](first, last In, dFirst Out, v T3, add BinaryOperation[T3, T2, T3], op UnaryOperation[T1, T2]) Out

TransformInclusiveScanBy transforms each element in the range [first, last) with op, then computes an inclusive prefix sum operation using v=add(v,cur) for the range [first, last), using v as the initial value (if provided), and writes the results to the range beginning at dFirst. "inclusive" means that the i-th input element is included in the i-th sum.

func Unique

func Unique[T comparable, It ForwardReadWriter[T, It]](first, last It) It

Unique eliminates all but the first element from every consecutive group of equivalent elements from the range [first, last) and returns a past-the-end iterator for the new logical end of the range.

func UniqueCopy

func UniqueCopy[T comparable, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out) Out

UniqueCopy copies the elements from the range [first, last), to another range beginning at dFirst in such a way that there are no consecutive equal elements.

Only the first element of each group of equal elements is copied.

func UniqueCopyIf

func UniqueCopyIf[T any, In InputIter[T, In], Out OutputIter[T]](first, last In, dFirst Out, eq EqComparer[T, T]) Out

UniqueCopyIf copies the elements from the range [first, last), to another range beginning at dFirst in such a way that there are no consecutive equal elements.

Only the first element of each group of equal elements is copied. Elements are compared using the given binary comparer eq.

func UniqueIf

func UniqueIf[T any, It ForwardReadWriter[T, It]](first, last It, eq EqComparer[T, T]) It

UniqueIf eliminates all but the first element from every consecutive group of equivalent elements from the range [first, last) and returns a past-the-end iterator for the new logical end of the range.

Elements are compared using the given binary comparer eq.

func UpperBound

func UpperBound[T Ordered, It ForwardReader[T, It]](first, last It, v T) It

UpperBound returns an iterator pointing to the first element in the range [first, last) that is greater than value, or last if no such element is found.

func UpperBoundBy

func UpperBoundBy[T any, It ForwardReader[T, It]](first, last It, v T, less LessComparer[T]) It

UpperBoundBy returns an iterator pointing to the first element in the range [first, last) that is greater than value, or last if no such element is found.

Elements are compared using the given binary comparer less.

Types

type BinaryOperation

type BinaryOperation[T1, T2, T3 any] func(T1, T2) T3

BinaryOperation transforms 2 values to 1 value.

type EqComparer

type EqComparer[T1, T2 any] func(T1, T2) bool

EqComparer checks if first value equals to the second value.

type Generator

type Generator[T any] func() T

Generator creates a value on each call.

type IteratorFunction

type IteratorFunction[T any] func(T)

IteratorFunction apply some actions to a value.

func ForEach

func ForEach[T any, It InputIter[T, It]](first, last It, f IteratorFunction[T]) IteratorFunction[T]

ForEach applies the given function f to the result of dereferencing every iterator in the range [first, last), in order.

func ForEachN

func ForEachN[T any, It InputIter[T, It]](first It, n int, f IteratorFunction[T]) IteratorFunction[T]

ForEachN applies the given function f to the result of dereferencing every iterator in the range [first, first + n), in order.

type LessComparer

type LessComparer[T any] func(T, T) bool

LessComparer checks if first value is less than the second value.

type ThreeWayComparer

type ThreeWayComparer[T1, T2 any] func(T1, T2) int

ThreeWayComparer compares 2 values, returns 1 if first>second, 0 if first=second, -1 if first<second.

type UnaryOperation

type UnaryOperation[T1, T2 any] func(T1) T2

UnaryOperation transforms a value to another.

type UnaryPredicate

type UnaryPredicate[T any] func(T) bool

UnaryPredicate checks if a value satisfy condition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL