kkewwei commented on code in PR #16896:
URL: https://github.com/apache/lucene/pull/16896#discussion_r4412165211
##########
lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90DocValuesProducer.java:
##########
@@ -547,21 +547,34 @@ static void rangeIntoBitSet(
* values satisfy {@code stored = raw * mul + delta}. Returns {@code
{encodedMin, encodedMax}} or
* {@code null} if the range is empty (no raw value can match).
*/
- private static long[] transformGcdBounds(long minValue, long maxValue, long
mul, long delta) {
+ static long[] transformGcdBounds(
+ long minValue, long maxValue, long mul, long delta, int bitsPerValue) {
assert mul > 0;
- long encodedMin = saturatingShiftLower(minValue, delta);
- long encodedMax = saturatingShiftUpper(maxValue, delta);
- if (mul != 1) {
- encodedMin = Math.ceilDiv(encodedMin, mul);
- encodedMax = Math.floorDiv(encodedMax, mul);
+ if (maxValue < delta) {
+ return null;
}
- encodedMin = Math.max(0, encodedMin);
+ assert canTransformGcdBounds(minValue, maxValue, delta, bitsPerValue);
+ long encodedMin = minValue <= delta ? 0 : Math.ceilDiv(minValue - delta,
mul);
+ long encodedMax =
+ maxValue == Long.MAX_VALUE ? Long.MAX_VALUE : Math.floorDiv(maxValue -
delta, mul);
if (encodedMin > encodedMax) {
return null;
}
return new long[] {encodedMin, encodedMax};
}
+ /** Checks whether query bounds can be safely transformed to encoded bounds.
*/
+ static boolean canTransformGcdBounds(long minValue, long maxValue, long
delta, int bitsPerValue) {
Review Comment:
1. delta >= 0:
minValue <= delta -> encodedMin = 0
maxValue < delta -> empty range
otherwise -> subtraction is safe
We can see it's aways safe to transform gcdBounds for the case
2. delta < 0:
minValue <= delta
-> encodedMin = 0
maxValue < delta
-> empty range
(minValue/maxValue) <= Long.MAX_VALUE + delta -> subtraction is
safe
otherwise
-> fallback
3. delta < 0 && maxValue == Long.MAX_VALUE:
bitsPerValue < 64 -> encodedMax = Long.MAX_VALUE
otherwise -> fallback
Special case3: when bitsPerValue < 64, the stored value must be <
Long.MAX_VALUE, encodedMax = Long.MAX_VALUE is safe
--
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]