rash67 commented on code in PR #13086:
URL: https://github.com/apache/druid/pull/13086#discussion_r970271401
##########
extensions-contrib/compressed-bigdecimal/src/main/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimal.java:
##########
@@ -276,13 +278,48 @@ protected static <S> int signumInternal(int size, S rhs,
ToIntBiFunction<S, Inte
*/
@Override
public int compareTo(CompressedBigDecimal o)
+ {
+ return compareTo(o, false);
+ }
+
+ public int compareTo(CompressedBigDecimal o, boolean expectOptimized)
{
if (super.equals(o)) {
return 0;
+ } else if (getScale() == o.getScale() && getArraySize() ==
o.getArraySize()) {
+ return compareCompressedBigDecimal(this, o, getArraySize());
+ } else {
+ if (expectOptimized) {
+ throw new RE("expected optimized path");
+ }
+
+ return this.toBigDecimal().compareTo(o.toBigDecimal());
+ }
+ }
+
+ public static int compareCompressedBigDecimal(CompressedBigDecimal lhs,
CompressedBigDecimal rhs, int length)
+ {
+ int[] result = new int[length];
+ int borrow = 0;
+
+ for (int i = 0; i < length; i++) {
+ long x = (INT_MASK & lhs.getArrayEntry(i)) - (INT_MASK &
rhs.getArrayEntry(i)) - borrow;
+ borrow = 0;
+
+ if (x < 0) {
+ borrow = 1;
+ x += 1L << 32;
+ }
+
+ result[i] = (int) x;
}
- return this.toBigDecimal().compareTo(o.toBigDecimal());
+
+ int signum = signumInternal(result.length, result, (r, i) -> r[i]);
Review Comment:
not sure if i should create a concrete class or concrete impl of
signumInternal for this case to avoid megamorphic callsite for the lambda
passed in?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]