View source code
Display the source code in std/algorithm/searching.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Module std.algorithm.searching
This is a submodule of std.algorithm. It contains generic searching algorithms.
Function Name | Description |
---|---|
all |
returns true because all elements
are positive |
any |
returns true because at least one
element is positive |
balancedParens |
returns true because the
string has balanced parentheses. |
boyerMooreFinder |
returns "orld"
using the Boyer-Moore algorithm. |
canFind |
returns true . |
count |
Counts elements that are equal to a specified value or satisfy a
predicate. returns 2 and
returns 1 . |
countUntil |
returns the number of steps taken in a to
reach b ; for example, returns
4 . |
commonPrefix |
returns "para" . |
endsWith |
returns true . |
find |
returns "orld" using linear search.
(For binary search refer to std.range.sortedRange.) |
findAdjacent |
returns the subrange starting with
two equal adjacent elements, i.e. [3, 3, 4] . |
findAmong |
returns "cd" because 'c' is
among "qcx" . |
findSkip |
If a = "abcde" , then returns false and
leaves a unchanged, whereas advances a
to "cde" and returns true . |
findSplit |
returns the three ranges "abc" ,
"de" , and "fg" . |
findSplitAfter |
returns the two ranges
"abcde" and "fg" . |
findSplitBefore |
returns the two ranges "abc"
and "defg" . |
minCount |
returns tuple(1, 3) . |
minPos |
returns the subrange [1, 3, 4, 1] ,
i.e., positions the range at the first occurrence of its minimal
element. |
mismatch |
mismatch("parakeet", "parachute") returns the two ranges
"keet" and "chute" . |
skipOver |
Assume a = "blah" . Then leaves a
unchanged and returns false , whereas
advances a to refer to "ah" and returns true . |
startsWith |
returns true . |
until |
Lazily iterates a range until a specific value is found. |
Functions
Name | Description |
---|---|
balancedParens
|
Checks whether has "balanced parentheses", i.e. all instances
of are closed by corresponding instances of . The
parameter controls the nesting level allowed. The
most common uses are the default or 0 . In the latter case, no
nesting is allowed.
|
boyerMooreFinder
|
Sets up Boyer-Moore matching for use with below.
By default, elements are compared for equality.
|
commonPrefix
|
Returns the common prefix of two ranges. |
count
|
The first version counts the number of elements x in r for
which pred(x, value) is true . pred defaults to
equality. Performs Ο(haystack.length ) evaluations of pred .
|
countUntil
|
Counts elements in the given
forward range
until the given predicate is true for one of the given .
|
countUntil
|
Similar to the previous overload of , except that this one
evaluates only the predicate pred .
|
endsWith
|
Checks if the given range ends with (one of) the given needle(s).
The reciprocal of .
|
find
|
Finds in efficiently using the
Boyer-Moore method.
|
find
|
Finds the first occurrence of a forward range in another forward range. |
find
|
Advances the input range by calling haystack.popFront
until either pred(haystack.front) , or haystack.empty . Performs Ο(haystack.length ) evaluations of pred .
|
find
|
Finds an individual element in an input range. Elements of are compared with by using predicate pred . Performs Ο(walkLength( ) evaluations of pred .
|
find
|
Finds two or more into a . The predicate pred is used throughout to compare elements. By default, elements are
compared for equality.
|
findAdjacent
|
Advances until it finds the first two adjacent elements a ,
b that satisfy pred(a, b) . Performs Ο(r.length )
evaluations of pred .
|
findAmong
|
Searches the given range for an element that matches one of the given choices .
|
findSkip
|
Finds in and positions
right after the first occurrence of .
|
findSplit
|
These functions find the first occurrence of in and then split as follows.
|
findSplitAfter
|
These functions find the first occurrence of in and then split as follows.
|
findSplitBefore
|
These functions find the first occurrence of in and then split as follows.
|
minCount
|
Returns the minimum element of a range together with the number of
occurrences. The function can actually be used for counting the
maximum or any other ordering predicate (that's why maxCount is
not provided).
|
minPos
|
Returns the position of the minimum element of forward range , i.e. a subrange of starting at the position of its
smallest element and with the same ending as . The function
can actually be used for finding the maximum or any other ordering
predicate (that's why maxPos is not provided).
|
skipOver
|
Skip over the initial portion of the first given range that matches the second range, or do nothing if there is no match. |
skipOver
|
Skip over the first element of the given range if it matches the given element, otherwise do nothing. |
startsWith
|
Checks whether the given input range starts with (one of) the given needle(s). |
until
|
Lazily iterates until the element e for which
pred(e, is true.
|
Structs
Name | Description |
---|---|
BoyerMooreFinder
|
Sets up Boyer-Moore matching for use with below.
By default, elements are compared for equality.
|
Enums
Name | Description |
---|---|
OpenRight
|
Interval option specifier for (below) and others.
|
Templates
Name | Description |
---|---|
all
|
Checks if all of the elements verify pred .
|
any
|
Checks if any of the elements verifies pred .
! can be used to verify that none of the elements verify
pred .
|
canFind
|
Convenience function. Like find , but only returns whether or not the search
was successful.
|