Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Dec 11, 2024
1 parent b72805f commit dafcffc
Showing 1 changed file with 35 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.the_qa_company.qendpoint.core.util.io.CloseSuppressPath;
import com.the_qa_company.qendpoint.core.util.io.Closer;
import com.the_qa_company.qendpoint.core.util.io.IOUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.IOException;
Expand All @@ -39,29 +41,31 @@
* @author mario.arias
*/
public class Bitmap375Big extends Bitmap64Big {
private final boolean oldBinarySearch;

/**
* create disk version bitmap with in memory super index
*
* @param location location
* @param nbits number of bits
* @return bitmap
*/
private static final Logger logger = LoggerFactory.getLogger(Bitmap375Big.class);

private static final boolean oldBinarySearch;

{
static {
// check if the system property "useOldBinarySeearch" is set to true
String useOldBinarySearch = System.getProperty("useOldBinarySearch");
if (useOldBinarySearch != null && useOldBinarySearch.equalsIgnoreCase("true")) {
this.oldBinarySearch = true;
System.out.println("Using old binary search");
oldBinarySearch = true;
logger.debug("Using old binary search");
} else {
System.out.println("Using new binary search");
this.oldBinarySearch = false;
logger.debug("Using new binary search");
oldBinarySearch = false;
}

}

/**
* create disk version bitmap with in memory super index
*
* @param location location
* @param nbits number of bits
* @return bitmap
*/
public static Bitmap375Big disk(Path location, long nbits) {
return disk(location, nbits, false);
}
Expand Down Expand Up @@ -483,39 +487,33 @@ public static long binarySearchNew(LongArray arr, long val) {
long max = arr.getEstimatedLocationUpperBound(val);
long mid = arr.getEstimatedLocation(val, min, max);

// System.out.println("Searching for: " + val);
int step = 0;
int i = 0;
while (min + 1 < max) {
step++;
// print min, max, mid
// System.out.println("min: " + min + " max: " + max + " mid: " + mid);

long l = arr.get(mid);

if (l >= val) {
max = mid;

if (min + 1 < max && step > 1 && step < 4) {
long l1 = arr.get(min + 1);
if (l1 >= val) {
max = min + 1;
} else {
// is this actually correct?
min = min + 1;
}
// After the first iteration, the value that we are looking for is
// typically very close to the min value. Using linear search for
// the next two iterations improves the chances that we find the
// value faster than with binary search.
if (i == 1 || i == 2) {
long v = arr.get(min + 1);
if (v >= val) {
max = min + 1;
} else {
min = min + 1;
}

} else {
min = mid;
long v = arr.get(mid);
if (v >= val) {
max = mid;
} else {
min = mid;
}
}
mid = (min + max) / 2;
i++;
}
// System.out.println("Found after: " + step + " steps");

arr.updateEstimatedValueLocation(val, min);

// prevFound[index] = min;

return min;
}

Expand Down

0 comments on commit dafcffc

Please sign in to comment.