aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/compress
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-01-08 11:33:44 +0100
committerGitHub <noreply@github.com>2023-01-08 11:33:44 +0100
commit6cedb4636301e1348d64e58886fe135be8b2b527 (patch)
tree62b7e1e947697ddc92e410a0ed1b951e67302f3d /vespajlib/src/main/java/com/yahoo/compress
parent9fd55bd72ee01b27efa2a27b32bc416483d2fda0 (diff)
parentf1f3dba5e56f7b0d074a5557fc8967e22a715b6e (diff)
Merge pull request #21773 from vespa-engine/jonmv/multi-range-item-2
Jonmv/multi range item 2
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/compress')
-rw-r--r--vespajlib/src/main/java/com/yahoo/compress/IntegerCompressor.java9
1 files changed, 9 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/compress/IntegerCompressor.java b/vespajlib/src/main/java/com/yahoo/compress/IntegerCompressor.java
index 982ca309015..42178fa3ffd 100644
--- a/vespajlib/src/main/java/com/yahoo/compress/IntegerCompressor.java
+++ b/vespajlib/src/main/java/com/yahoo/compress/IntegerCompressor.java
@@ -10,10 +10,19 @@ import java.nio.ByteBuffer;
*/
public class IntegerCompressor {
+ public enum Mode { NONE, COMPRESSED, COMPRESSED_POSITIVE; }
+
+ public static Mode compressionMode(int min, int max) {
+ if (min >= 0 && max < 1 << 30) return Mode.COMPRESSED_POSITIVE;
+ if (min > -1 << 29 && max < 1 << 29) return Mode.COMPRESSED;
+ return Mode.NONE;
+ }
+
public static void putCompressedNumber(int n, ByteBuffer buf) {
int negative = n < 0 ? 0x80 : 0x0;
if (negative != 0) {
n = -n;
+ if (n == -n) --n; // underflow, caught as "too big" later.
}
if (n < (0x1 << 5)) {
byte b = (byte)(n | negative);