byte[] leftInnerClosedKey = getLeftClosedScanKey(leftKeyOpen, thisSubkeyLen);
byte[] rightInnerClosedKey = getRightClosedScanKey(rightKeyOpen, thisSubkeyLen);
if (Bytes.compareTo(leftInnerClosedKey, 0, thisSubkeyLen, rightInnerClosedKey, 0, thisSubkeyLen) > 0) {
Range r = new Range(leftKey, rightKey, true);
r.setKeyLen(keylen);
r.setLevelOffset(thisSubkeyLen);
r.setLevelLen(getSubkeyLen(i + 1) - thisSubkeyLen);
// TODO: this is wrong in general case, adjust
r.setLeftOpen(leftBound == null ? false : slice.isLeftOpen());
r.setRightOpen(rightBound == null ? false : slice.isRightOpen());
result[scans++] = r;
break;
}
// test for left gap
if (!HblUtil.test1s(leftKeyOpen, thisSubkeyLen, keylen - thisSubkeyLen)) {
// left gap scan
Range leftGapR = new Range(leftKey, leftInnerClosedKey, true, leftOpen, true);
leftGapR.setLevelOffset(thisSubkeyLen);
leftGapR.setLevelLen(subkeylen - thisSubkeyLen);
leftGapR.setSliceOperation(SliceOperation.ADD);
result[scans++] = leftGapR;
}
// test for right gap
if (!HblUtil.test0s(rightKeyOpen, thisSubkeyLen, keylen - thisSubkeyLen)) {
// right gap scan
byte[] rightStart = rightInnerClosedKey.clone();
HblUtil.incrementKey(rightStart, 0, thisSubkeyLen);
Range rightGapR = new Range(rightStart, rightKey, true, true, rightOpen);
rightGapR.setKeyLen(keylen);
rightGapR.setLevelOffset(thisSubkeyLen);
rightGapR.setLevelLen(subkeylen - thisSubkeyLen);
rightGapR.setSliceOperation(SliceOperation.ADD);
result[scans++] = rightGapR;
}
// more upkeys?
if (i == 1) {
// main scan
Range r = new Range(leftInnerClosedKey, rightInnerClosedKey, true, false, false);
r.setKeyLen(keylen);
r.setLevelOffset(0);
r.setLevelLen(thisSubkeyLen);
r.setSliceOperation(SliceOperation.ADD);
result[scans++] = r;
break;
} else {
leftKey = leftInnerClosedKey;