Replace O(N^2) cost bitset clearing with O(N)

This commit is contained in:
Mike McCandless 2016-03-11 18:43:34 -05:00
parent 007d41c9f5
commit 684b222221
1 changed files with 11 additions and 4 deletions

View File

@ -1126,6 +1126,14 @@ public class BKDWriter implements Closeable {
byte[] maxSplitPackedValue = new byte[packedBytesLength];
System.arraycopy(maxPackedValue, 0, maxSplitPackedValue, 0, packedBytesLength);
// When we are on this dim, below, we clear the ordBitSet:
int dimToClear;
if (numDims - 1 == splitDim) {
dimToClear = numDims - 2;
} else {
dimToClear = numDims - 1;
}
for(int dim=0;dim<numDims;dim++) {
if (dim == splitDim) {
@ -1152,6 +1160,9 @@ public class BKDWriter implements Closeable {
if (ordBitSet.get(ord)) {
rightPointWriter.append(packedValue, ord, docID);
nextRightCount++;
if (dim == dimToClear) {
ordBitSet.clear(ord);
}
} else {
leftPointWriter.append(packedValue, ord, docID);
}
@ -1164,10 +1175,6 @@ public class BKDWriter implements Closeable {
}
}
if (numDims > 1) {
ordBitSet.clear(0, pointCount);
}
// Recurse on left tree:
build(2*nodeID, leafNodeOffset, leftSlices,
ordBitSet, out,