count

Performs a linear scan of haystack from [0 .. haystack.length$(RP), returning a count of the number of elements matching needle. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

  1. size_t count(T[] haystack, T needle, Pred pred)
    size_t
    count
    (
    in T[] haystack
    ,
    in T needle
    ,
    Pred pred = Pred.init
    )
  2. size_t count(Buffer!(T) haystack, T needle, Pred pred)

Parameters

haystack T[]

The array to scan.

needle T

The pattern to match.

pred Pred

The evaluation predicate, which should return true if e1 is equal to e2 and false if not. This predicate may be any callable type.

Return Value

Type: size_t

The number of elements matching needle.

Examples

test!("==")(count("gbbbi", 'b'), 3);
auto buffer = createBuffer("gbbbi");
test!("==")(count(buffer, 'b'), 3);

Meta