Use Arrays.binarySearch()
This commit is contained in:
parent
612d842931
commit
1804df31a7
|
@ -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;
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue