mismatch

Performs a parallel linear scan of arr and arr_against from [0 .. N$(RP) where N = min(arr.length, arr_against.length), returning the index of the first element in arr which does not match the corresponding element in arr_against or N if no mismatch occurs. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

If the input arrays are not sorted in the same way, or they have different number of duplicate items, see bsubset.

  1. size_t mismatch(T[] arr, T[] arr_against, Pred pred)
    size_t
    mismatch
    (
    in T[] arr
    ,,
    Pred pred = Pred.init
    )
  2. size_t mismatch(Buffer!(T) arr, Buffer!(T) arr_against, Pred pred)

Parameters

arr T[]

The array to evaluate.

arr_against T[]

The array to match against.

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 index of the first mismatch or N if the first N elements of arr and arr_against match, where N = min$(LP)arr.length, arr_against.length$(RP).

Examples

// result must not change from swapping argument order:
test!("==")(mismatch("abcxefg", "abcdefg"), 3);
test!("==")(mismatch("abcdefg", "abcxefg"), 3);
// result must not change from swapping argument order:
auto buffer1 = createBuffer("abcxefg");
auto buffer2 = createBuffer("abcdefg");
test!("==")( mismatch(buffer1, buffer2), 3 );
test!("==")( mismatch(buffer2, buffer1), 3 );

Meta