Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
// Written in the D programming language.
This package implements generic algorithms oriented towards the processing of
sequences. Sequences processed by these functions define range-based
interfaces. See also $(MREF_ALTTEXT Reference on ranges, std, range) and
$(HTTP, tutorial on ranges).
$(SCRIPT inhibitQuickIndex = 1;)
Algorithms are categorized into the following submodules:
$(DIVC quickindex,
$(TR $(TH Submodule) $(TH Functions)
$(TDNW $(SUBMODULE Searching, searching))
$(SUBREF searching, all)
$(SUBREF searching, any)
$(SUBREF searching, balancedParens)
$(SUBREF searching, boyerMooreFinder)
$(SUBREF searching, canFind)
$(SUBREF searching, commonPrefix)
$(SUBREF searching, count)
$(SUBREF searching, countUntil)
$(SUBREF searching, endsWith)
$(SUBREF searching, find)
$(SUBREF searching, findAdjacent)
$(SUBREF searching, findAmong)
$(SUBREF searching, findSkip)
$(SUBREF searching, findSplit)
$(SUBREF searching, findSplitAfter)
$(SUBREF searching, findSplitBefore)
$(SUBREF searching, minCount)
$(SUBREF searching, maxCount)
$(SUBREF searching, minElement)
$(SUBREF searching, maxElement)
$(SUBREF searching, minIndex)
$(SUBREF searching, maxIndex)
$(SUBREF searching, minPos)
$(SUBREF searching, maxPos)
$(SUBREF searching, skipOver)
$(SUBREF searching, startsWith)
$(SUBREF searching, until)
$(TDNW $(SUBMODULE Comparison, comparison))
$(SUBREF comparison, among)
$(SUBREF comparison, castSwitch)
$(SUBREF comparison, clamp)
$(SUBREF comparison, cmp)
$(SUBREF comparison, either)
$(SUBREF comparison, equal)
$(SUBREF comparison, isPermutation)
$(SUBREF comparison, isSameLength)
$(SUBREF comparison, levenshteinDistance)
$(SUBREF comparison, levenshteinDistanceAndPath)
$(SUBREF comparison, max)
$(SUBREF comparison, min)
$(SUBREF comparison, mismatch)
$(SUBREF comparison, predSwitch)
$(TDNW $(SUBMODULE Iteration, iteration))
$(SUBREF iteration, cache)
$(SUBREF iteration, cacheBidirectional)
$(SUBREF iteration, chunkBy)
$(SUBREF iteration, cumulativeFold)
$(SUBREF iteration, each)
$(SUBREF iteration, filter)
$(SUBREF iteration, filterBidirectional)
$(SUBREF iteration, fold)
$(SUBREF iteration, group)
$(SUBREF iteration, joiner)
$(SUBREF iteration, map)
$(SUBREF iteration, mean)
$(SUBREF iteration, permutations)
$(SUBREF iteration, reduce)
$(SUBREF iteration, splitWhen)
$(SUBREF iteration, splitter)
$(SUBREF iteration, substitute)
$(SUBREF iteration, sum)
$(SUBREF iteration, uniq)
$(TDNW $(SUBMODULE Sorting, sorting))
$(SUBREF sorting, completeSort)
$(SUBREF sorting, isPartitioned)
$(SUBREF sorting, isSorted)
$(SUBREF sorting, isStrictlyMonotonic)
$(SUBREF sorting, ordered)
$(SUBREF sorting, strictlyOrdered)
$(SUBREF sorting, makeIndex)
$(SUBREF sorting, merge)
$(SUBREF sorting, multiSort)
$(SUBREF sorting, nextEvenPermutation)
$(SUBREF sorting, nextPermutation)
$(SUBREF sorting, nthPermutation)
$(SUBREF sorting, partialSort)
$(SUBREF sorting, partition)
$(SUBREF sorting, partition3)
$(SUBREF sorting, schwartzSort)
$(SUBREF sorting, sort)
$(SUBREF sorting, topN)
$(SUBREF sorting, topNCopy)
$(SUBREF sorting, topNIndex)
$(TDNW Set operations $(BR)($(SUBMODULE setops, setops)))
$(SUBREF setops, cartesianProduct)
$(SUBREF setops, largestPartialIntersection)
$(SUBREF setops, largestPartialIntersectionWeighted)
$(SUBREF setops, multiwayMerge)
$(SUBREF setops, multiwayUnion)
$(SUBREF setops, setDifference)
$(SUBREF setops, setIntersection)
$(SUBREF setops, setSymmetricDifference)
$(TDNW $(SUBMODULE Mutation, mutation))
$(SUBREF mutation, bringToFront)
$(SUBREF mutation, copy)
$(SUBREF mutation, fill)
$(SUBREF mutation, initializeAll)
$(SUBREF mutation, move)
$(SUBREF mutation, moveAll)
$(SUBREF mutation, moveSome)
$(SUBREF mutation, moveEmplace)
$(SUBREF mutation, moveEmplaceAll)
$(SUBREF mutation, moveEmplaceSome)
$(SUBREF mutation, remove)
$(SUBREF mutation, reverse)
$(SUBREF mutation, strip)
$(SUBREF mutation, stripLeft)
$(SUBREF mutation, stripRight)
$(SUBREF mutation, swap)
$(SUBREF mutation, swapRanges)
$(SUBREF mutation, uninitializedFill)
Many functions in this package are parameterized with a $(GLOSSARY predicate).
The predicate may be any suitable callable type
(a function, a delegate, a $(GLOSSARY functor), or a lambda), or a
compile-time string. The string may consist of $(B any) legal D
expression that uses the symbol `a` (for unary functions) or the
symbols `a` and `b` (for binary functions). These names will NOT
interfere with other homonym symbols in user code because they are
evaluated in a different context. The default for all binary
comparison predicates is `"a == b"` for unordered operations and
`"a < b"` for ordered operations.
int[] a = ...;
static bool greater(int a, int b)
return a > b;
sort!greater(a); // predicate as alias
sort!((a, b) => a > b)(a); // predicate as a lambda.
sort!"a > b"(a); // predicate as string
// (no ambiguity with array name)
sort(a); // no predicate, "a < b" is implicit
SUBMODULE = $(MREF_ALTTEXT $1, std, algorithm, $2)
SUBREF = $(REF_ALTTEXT $(TT $2), $2, std, algorithm, $1)$(NBSP)
Copyright: Andrei Alexandrescu 2008-.
License: $(HTTP, Boost License 1.0).
Authors: $(HTTP, Andrei Alexandrescu)
Source: $(PHOBOSSRC std/algorithm/package.d)
module std.algorithm;
public import std.algorithm.comparison;
public import std.algorithm.iteration;
public import std.algorithm.mutation;
public import std.algorithm.searching;
public import std.algorithm.setops;
public import std.algorithm.sorting;
static import std.functional;