Skip to content

Commit

Permalink
HBASE-26566 Optimize determine E step in OrderedBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
YutSean committed Dec 13, 2021
1 parent 8bca21b commit 915ecef
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,11 @@ private static int encodeNumericSmall(PositionedByteRange dst, BigDecimal val) {
}

// normalize abs(val) to determine E
while (abs.compareTo(EN10) < 0) { abs = abs.movePointRight(8); e += 4; }
while (abs.compareTo(EN2) < 0) { abs = abs.movePointRight(2); e++; }
int zerosBeforeFirstNonZero = abs.scale() - abs.precision();
int lengthToMoveRight = zerosBeforeFirstNonZero % 2 ==
0 ? zerosBeforeFirstNonZero : zerosBeforeFirstNonZero - 1;
e = lengthToMoveRight / 2;
abs = abs.movePointRight(lengthToMoveRight);

putVaruint64(dst, e, !isNeg); // encode appropriate E value.

Expand Down Expand Up @@ -716,9 +719,10 @@ private static int encodeNumericLarge(PositionedByteRange dst, BigDecimal val) {
}

// normalize abs(val) to determine E
while (abs.compareTo(E32) >= 0 && e <= 350) { abs = abs.movePointLeft(32); e +=16; }
while (abs.compareTo(E8) >= 0 && e <= 350) { abs = abs.movePointLeft(8); e+= 4; }
while (abs.compareTo(BigDecimal.ONE) >= 0 && e <= 350) { abs = abs.movePointLeft(2); e++; }
int integerDigits = abs.precision() - abs.scale();
int lengthToMoveLeft = integerDigits % 2 == 0 ? integerDigits : integerDigits + 1;
e = lengthToMoveLeft / 2;
abs = abs.movePointLeft(lengthToMoveLeft);

// encode appropriate header byte and/or E value.
if (e > 10) { /* large number, write out {~,}E */
Expand Down

0 comments on commit 915ecef

Please sign in to comment.