The OpenD Programming Language

find

Finds needle in haystack efficiently using the Boyer-Moore method.

  1. InputRange find(InputRange haystack)
  2. InputRange find(InputRange haystack, Element needle)
  3. R1 find(R1 haystack, R2 needle)
  4. Tuple!(Range, size_t) find(Range haystack, Needles needles)
  5. RandomAccessRange find(RandomAccessRange haystack, BoyerMooreFinder!(pred, InputRange) needle)
    RandomAccessRange
    find
    (
    RandomAccessRange
    alias pred
    InputRange
    )
    (
    RandomAccessRange haystack
    ,
    scope BoyerMooreFinder!(pred, InputRange) needle
    )

Parameters

haystack RandomAccessRange

A random-access range with length and slicing.

needle BoyerMooreFinder!(pred, InputRange)

Return Value

Type: RandomAccessRange

haystack advanced such that needle is a prefix of it (if no such position exists, returns haystack advanced to termination).

Examples

import std.range.primitives : empty;
int[] a = [ -1, 0, 1, 2, 3, 4, 5 ];
int[] b = [ 1, 2, 3 ];

assert(find(a, boyerMooreFinder(b)) == [ 1, 2, 3, 4, 5 ]);
assert(find(b, boyerMooreFinder(a)).empty);

Meta