Skip to content

Commit 1a63fcd

Browse files
committed
Some more tweaking
1 parent e9a1e43 commit 1a63fcd

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private void getBestBFromData(int[] in, int pos) {
122122
int thiscost = cexcept * OVERHEAD_OF_EACH_EXCEPT
123123
+ cexcept * (bestbbestcexceptmaxb[2] - b) + b
124124
* BLOCK_SIZE + 8;
125+
if(bestbbestcexceptmaxb[2] - b == 1) thiscost -= cexcept;
125126
if (thiscost < bestcost) {
126127
bestcost = thiscost;
127128
bestbbestcexceptmaxb[0] = b;
@@ -142,7 +143,6 @@ private void encodePage(int[] in, IntWrapper inpos, int thissize,
142143

143144
int tmpinpos = inpos.get();
144145
for (final int finalinpos = tmpinpos + thissize - BLOCK_SIZE; tmpinpos <= finalinpos; tmpinpos += BLOCK_SIZE) {
145-
146146
getBestBFromData(in, tmpinpos);
147147
final int tmpbestb = bestbbestcexceptmaxb[0];
148148
byteContainer.put((byte)bestbbestcexceptmaxb[0]);
@@ -187,17 +187,16 @@ private void encodePage(int[] in, IntWrapper inpos, int thissize,
187187
byteContainer.asIntBuffer().get(out, tmpoutpos, howmanyints);
188188
tmpoutpos += howmanyints;
189189
int bitmap = 0;
190-
for (int k = 1; k <= 32; ++k) {
190+
for (int k = 2; k <= 32; ++k) {
191191
if (dataPointers[k] != 0)
192192
bitmap |= (1 << (k - 1));
193193
}
194194
out[tmpoutpos++] = bitmap;
195195

196-
for (int k = 1; k <= 32; ++k) {
196+
for (int k = 2; k <= 32; ++k) {
197197
if (dataPointers[k] != 0) {
198198
out[tmpoutpos++] = dataPointers[k];// size
199199
int j = 0;
200-
201200
for (; j + 31 < dataPointers[k]; j += 32) {
202201
BitPacking.fastpack(dataTobePacked[k],
203202
j, out, tmpoutpos, k);
@@ -250,7 +249,7 @@ private void decodePage(int[] in, IntWrapper inpos, int[] out,
250249
inexcept += (bytesize + 3)/ 4;
251250

252251
final int bitmap = in[inexcept++];
253-
for (int k = 1; k <= 32; ++k) {
252+
for (int k = 2; k <= 32; ++k) {
254253
if ((bitmap & (1 << (k - 1))) != 0) {
255254
int size = in[inexcept++];
256255
if (dataTobePacked[k].length < size)
@@ -282,14 +281,20 @@ private void decodePage(int[] in, IntWrapper inpos, int[] out,
282281
tmpinpos += b;
283282
}
284283
if (cexcept > 0) {
285-
final int maxbits = byteContainer.get();
286-
final int index = maxbits - b;
284+
final int maxbits = byteContainer.get();
285+
final int index = maxbits - b;
286+
if(index == 1) {
287287
for (int k = 0; k < cexcept; ++k) {
288-
final int pos = byteContainer.get() &0xFF;
289-
final int exceptvalue = dataTobePacked[index][dataPointers[index]++];
290-
out[pos + tmpoutpos] |= exceptvalue << b;
288+
final int pos = byteContainer.get() &0xFF;
289+
out[pos + tmpoutpos] |= 1 << b;
290+
}
291+
} else {
292+
for (int k = 0; k < cexcept; ++k) {
293+
final int pos = byteContainer.get() &0xFF;
294+
final int exceptvalue = dataTobePacked[index][dataPointers[index]++];
295+
out[pos + tmpoutpos] |= exceptvalue << b;
291296
}
292-
297+
}
293298
}
294299
}
295300
outpos.set(tmpoutpos);

0 commit comments

Comments
 (0)