indexOf on sorted lists should return the first match

This commit is contained in:
2017-12-09 15:50:55 +01:00
parent 14181822c9
commit 3dd1955749
2 changed files with 11 additions and 2 deletions

View File

@@ -616,7 +616,10 @@ public final class IntList implements Serializable, Cloneable {
int result = -1;
if (sorted) {
final int insertionPoint = Arrays.binarySearch(data, offset, size(), value);
int insertionPoint = Arrays.binarySearch(data, offset, size(), value);
while (insertionPoint > 0 && insertionPoint > offset && data[insertionPoint - 1] == value) {
insertionPoint--;
}
result = insertionPoint < 0 ? -1 : insertionPoint;
} else {
for (int i = offset; i < size; i++) {
@@ -867,5 +870,4 @@ public final class IntList implements Serializable, Cloneable {
return result;
}
}