Use Arrays.binarySearch()

This commit is contained in:
xynngh 2019-07-09 19:35:32 +04:00
parent 612d842931
commit 1804df31a7
2 changed files with 4 additions and 17 deletions

View File

@ -9,6 +9,7 @@ import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import dummydomain.yetanothercallblocker.sia.utils.LittleEndianDataInputStream;
@ -38,21 +39,7 @@ public abstract class AbstractDatabaseDataSlice<T> {
protected int indexOf(long number) {
if (numberOfItems > 0) {
int low = 0;
int high = numberOfItems - 1;
while (low <= high) {
int mid = (high + low) / 2;
long num = numbers[mid];
if (num < number) {
low = mid + 1;
} else if (num > number) {
high = mid - 1;
} else {
return mid;
}
}
return Arrays.binarySearch(numbers, number);
}
return -1;

View File

@ -154,12 +154,12 @@ public class CommunityDatabaseDataSlice extends AbstractDatabaseDataSlice<Commun
if (newSlice != null) {
if (this.numberOfItems > 0) {
for (long n : newSlice.numbers) {
if (indexOf(n) == -1) {
if (indexOf(n) < 0) {
newNumberOfItems++;
}
}
for (long n : newSlice.numbersToDelete) {
if (indexOf(n) == -1) {
if (indexOf(n) < 0) {
newNumberOfItems++;
}
}