mismatch

fun mismatch(a: ByteArray, aOffset: Int, b: ByteArray, bOffset: Int, len: Int): Int

Returns the first index i (0 ≤ i < len) for which aaOffset + i != bbOffset + i. If no such index exists, returns -1.


fun mismatch(a: ByteArray, aFromIndex: Int, aToIndex: Int, b: ByteArray, bFromIndex: Int, bToIndex: Int): Int

Finds and returns the relative index of the first mismatch between two byte arrays over the specified ranges, otherwise return -1 if no mismatch is found. The index will be in the range of 0 (inclusive) up to the length (inclusive) of the smaller range.

If the two arrays, over the specified ranges, share a common prefix then the returned relative index is the length of the common prefix and it follows that there is a mismatch between the two elements at that relative index within the respective arrays. If one array is a proper prefix of the other, over the specified ranges, then the returned relative index is the length of the smaller range and it follows that the relative index is only valid for the array with the larger range. Otherwise, there is no mismatch.

Two non-null arrays, a and b with specified ranges [aFromIndex, aToIndex) and [bFromIndex, bToIndex) respectively, share a common prefix of length pl if the following expression is true:

`pl >= 0 &&
pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
a[aFromIndex + pl] != b[bFromIndex + pl]
`
*

Note that a common prefix length of 0 indicates that the first elements from each array mismatch.

Two non-null arrays, a and b with specified ranges [aFromIndex, aToIndex) and [bFromIndex, bToIndex) respectively, share a proper prefix if the following expression is true:

`(aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
`
*

Return

the relative index of the first mismatch between the two arrays over the specified ranges, otherwise -1.

Since

9

Parameters

a

the first array to be tested for a mismatch

aFromIndex

the index (inclusive) of the first element in the first array to be tested

aToIndex

the index (exclusive) of the last element in the first array to be tested

b

the second array to be tested for a mismatch

bFromIndex

the index (inclusive) of the first element in the second array to be tested

bToIndex

the index (exclusive) of the last element in the second array to be tested

Throws

if aFromIndex > aToIndex or if bFromIndex > bToIndex

ArrayIndexOutOfBoundsException

if aFromIndex < 0 or aToIndex > a.length or if bFromIndex < 0 or bToIndex > b.length

if either array is null


fun mismatch(a: IntArray, aFromIndex: Int, aToIndex: Int, b: IntArray, bFromIndex: Int, bToIndex: Int): Int

Finds and returns the relative index of the first mismatch between two int arrays over the specified ranges, otherwise return -1 if no mismatch is found. The index will be in the range of 0 (inclusive) up to the length (inclusive) of the smaller range.

If the two arrays, over the specified ranges, share a common prefix then the returned relative index is the length of the common prefix and it follows that there is a mismatch between the two elements at that relative index within the respective arrays. If one array is a proper prefix of the other, over the specified ranges, then the returned relative index is the length of the smaller range and it follows that the relative index is only valid for the array with the larger range. Otherwise, there is no mismatch.

Two non-null arrays, a and b with specified ranges [aFromIndex, aToIndex) and [bFromIndex, bToIndex) respectively, share a common prefix of length pl if the following expression is true:

`pl >= 0 &&
pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
a[aFromIndex + pl] != b[bFromIndex + pl]
`
*

Note that a common prefix length of 0 indicates that the first elements from each array mismatch.

Two non-null arrays, a and b with specified ranges [aFromIndex, aToIndex) and [bFromIndex, bToIndex) respectively, share a proper prefix if the following expression is true:

`(aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
`
*

Return

the relative index of the first mismatch between the two arrays over the specified ranges, otherwise -1.

Since

9

Parameters

a

the first array to be tested for a mismatch

aFromIndex

the index (inclusive) of the first element in the first array to be tested

aToIndex

the index (exclusive) of the last element in the first array to be tested

b

the second array to be tested for a mismatch

bFromIndex

the index (inclusive) of the first element in the second array to be tested

bToIndex

the index (exclusive) of the last element in the second array to be tested

Throws

if aFromIndex > aToIndex or if bFromIndex > bToIndex

ArrayIndexOutOfBoundsException

if aFromIndex < 0 or aToIndex > a.length or if bFromIndex < 0 or bToIndex > b.length

if either array is null


fun mismatch(a: IntArray, aFromIndex: Int, b: IntArray, bFromIndex: Int, len: Int): Int

Returns the first index (0 ≤ i < len) at which the elements of the two IntArrays differ, when compared over the given length starting at aFromIndex and bFromIndex respectively. Returns -1 if no mismatch is found.


fun mismatch(a: CharArray, aFromIndex: Int, aToIndex: Int, b: CharArray, bFromIndex: Int, bToIndex: Int): Int

Finds and returns the relative index of the first mismatch between two {@code char} arrays over the specified ranges, otherwise return -1 if no mismatch is found. The index will be in the range of 0 (inclusive) up to the length (inclusive) of the smaller range.

If the two arrays, over the specified ranges, share a common prefix then the returned relative index is the length of the common prefix and it follows that there is a mismatch between the two elements at that relative index within the respective arrays. If one array is a proper prefix of the other, over the specified ranges, then the returned relative index is the length of the smaller range and it follows that the relative index is only valid for the array with the larger range. Otherwise, there is no mismatch.

Two non-{@code null} arrays, {@code a} and {@code b} with specified ranges [{@code aFromIndex}, {@code aToIndex}) and [{@code bFromIndex}, {@code bToIndex}) respectively, share a common prefix of length {@code pl} if the following expression is true:

{@code
     pl >= 0 &&
     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
     a[aFromIndex + pl] != b[bFromIndex + pl]
}
Note that a common prefix length of {@code 0} indicates that the first elements from each array mismatch.

Two non-{@code null} arrays, {@code a} and {@code b} with specified ranges [{@code aFromIndex}, {@code aToIndex}) and [{@code bFromIndex}, {@code bToIndex}) respectively, share a proper prefix if the following expression is true:

{@code
     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
}

Return

the relative index of the first mismatch between the two arrays over the specified ranges, otherwise {@code -1}.

Since

9

Parameters

a

the first array to be tested for a mismatch

aFromIndex

the index (inclusive) of the first element in the first array to be tested

aToIndex

the index (exclusive) of the last element in the first array to be tested

b

the second array to be tested for a mismatch

bFromIndex

the index (inclusive) of the first element in the second array to be tested

bToIndex

the index (exclusive) of the last element in the second array to be tested

Throws

     if {@code aFromIndex > aToIndex} or
     if {@code bFromIndex > bToIndex}
ArrayIndexOutOfBoundsException
     if {@code aFromIndex < 0 or aToIndex > a.length} or
     if {@code bFromIndex < 0 or bToIndex > b.length}
     if either array is {@code null}