Skip to content

Commit 6fc27d8

Browse files
committed
brush up
1 parent dadca96 commit 6fc27d8

2 files changed

Lines changed: 9 additions & 32 deletions

File tree

src/main/java/me/lemire/integercompression/DeltaZigzagBinaryPacking.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,11 @@ public void uncompress(
6565
int op = outPos.get();
6666
final int outPosLast = op + outLen;
6767
for (; op < outPosLast; op += BLOCK_LENGTH) {
68-
final int bits1 = (inBuf[ip] >>> 24);
69-
final int bits2 = (inBuf[ip] >>> 16) & 0xFF;
70-
final int bits3 = (inBuf[ip] >>> 8) & 0xFF;
71-
final int bits4 = (inBuf[ip] >>> 0) & 0xFF;
72-
++ip;
73-
ip += unpack(inBuf, ip, work, 0, bits1);
74-
ip += unpack(inBuf, ip, work, 32, bits2);
75-
ip += unpack(inBuf, ip, work, 64, bits3);
76-
ip += unpack(inBuf, ip, work, 96, bits4);
68+
int n = inBuf[ip++];
69+
ip += unpack(inBuf, ip, work, 0, (n >> 24) & 0x3F);
70+
ip += unpack(inBuf, ip, work, 32, (n >> 16) & 0x3F);
71+
ip += unpack(inBuf, ip, work, 64, (n >> 8) & 0x3F);
72+
ip += unpack(inBuf, ip, work, 96, (n >> 0) & 0x3F);
7773
ctx.decodeArray(work, 0, BLOCK_LENGTH, outBuf, op);
7874
}
7975

src/main/java/me/lemire/integercompression/DeltaZigzagEncoding.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public int encodeInt(int value) {
4040
public int[] encodeArray(int[] src, int srcoff, int length,
4141
int[] dst, int dstoff)
4242
{
43-
return encodeArray1(src, srcoff, length, dst, dstoff);
43+
for (int i = 0; i < length; ++i) {
44+
dst[dstoff + i] = encodeInt(src[srcoff + i]);
45+
}
46+
return dst;
4447
}
4548

4649
public int[] encodeArray(int[] src, int srcoff, int length,
@@ -56,28 +59,6 @@ public int[] encodeArray(int[] src, int offset, int length) {
5659
public int[] encodeArray(int[] src) {
5760
return encodeArray(src, 0, src.length, new int[src.length], 0);
5861
}
59-
60-
private int[] encodeArray1(int[] src, int srcoff, int length,
61-
int[] dst, int dstoff)
62-
{
63-
for (int i = 0; i < length; ++i) {
64-
dst[dstoff + i] = encodeInt(src[srcoff + i]);
65-
}
66-
return dst;
67-
}
68-
69-
private int[] encodeArray2(int[] src, int srcoff, int length,
70-
int[] dst, int dstoff)
71-
{
72-
int ctx = this.contextValue;
73-
for (int i = 0; i < length; ++i) {
74-
int n = src[srcoff + i] - ctx;
75-
ctx = src[srcoff + i];
76-
dst[dstoff + i] = (n << 1) ^ (n >> 31);
77-
}
78-
this.contextValue = ctx;
79-
return dst;
80-
}
8162
}
8263

8364
public static class Decoder extends Context {

0 commit comments

Comments
 (0)