| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,8 @@ | |||
| 6 | 6 | */ | |
| 7 | 7 | package me.lemire.integercompression; | |
| 8 | 8 | ||
| 9 | + import me.lemire.integercompression.skippable.SkippableIntegerCODEC; | ||
| 10 | + | ||
| 9 | 11 | /** | |
| 10 | 12 | * Scheme based on a commonly used idea: can be extremely fast. | |
| 11 | 13 | * It encodes integers in blocks of 128 integers. For arrays containing | |
@@ -35,17 +37,23 @@ | |||
| 35 | 37 | * | |
| 36 | 38 | * @author Daniel Lemire | |
| 37 | 39 | */ | |
| 38 | - public final class BinaryPacking implements IntegerCODEC { | ||
| 40 | + public final class BinaryPacking implements IntegerCODEC, SkippableIntegerCODEC { | ||
| 39 | 41 | ||
| 40 | 42 | @Override | |
| 41 | 43 | public void compress(int[] in, IntWrapper inpos, int inlength, | |
| 42 | 44 | int[] out, IntWrapper outpos) { | |
| 43 | - inlength = inlength / 128 * 128; | ||
| 44 | - if (inlength == 0) | ||
| 45 | - return; | ||
| 45 | + inlength = inlength / 128 * 128; | ||
| 46 | + if (inlength == 0) | ||
| 47 | + return; | ||
| 48 | + out[outpos.get()] = inlength; | ||
| 49 | + outpos.increment(); | ||
| 50 | + headlessCompress(in, inpos, inlength, out, outpos); | ||
| 51 | + } | ||
| 46 | 52 | ||
| 47 | - out[outpos.get()] = inlength; | ||
| 48 | - outpos.increment(); | ||
| 53 | + @Override | ||
| 54 | + public void headlessCompress(int[] in, IntWrapper inpos, int inlength, | ||
| 55 | + int[] out, IntWrapper outpos) { | ||
| 56 | + inlength = inlength / 128 * 128; | ||
| 49 | 57 | int tmpoutpos = outpos.get(); | |
| 50 | 58 | for (int s = inpos.get(); s < inpos.get() + inlength; s += 32 * 4) { | |
| 51 | 59 | final int mbits1 = Util.maxbits(in, s, 32); | |
@@ -78,6 +86,13 @@ public void uncompress(int[] in, IntWrapper inpos, int inlength, | |||
| 78 | 86 | return; | |
| 79 | 87 | final int outlength = in[inpos.get()]; | |
| 80 | 88 | inpos.increment(); | |
| 89 | + headlessUncompress(in,inpos, inlength,out,outpos,outlength); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Override | ||
| 93 | + public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, | ||
| 94 | + int[] out, IntWrapper outpos, int num) { | ||
| 95 | + final int outlength = num / 128 * 128; | ||
| 81 | 96 | int tmpinpos = inpos.get(); | |
| 82 | 97 | for (int s = outpos.get(); s < outpos.get() + outlength; s += 32 * 4) { | |
| 83 | 98 | final int mbits1 = (in[tmpinpos] >>> 24); | |
@@ -100,7 +115,6 @@ public void uncompress(int[] in, IntWrapper inpos, int inlength, | |||
| 100 | 115 | outpos.add(outlength); | |
| 101 | 116 | inpos.set(tmpinpos); | |
| 102 | 117 | } | |
| 103 | - | ||
| 104 | 118 | @Override | |
| 105 | 119 | public String toString() { | |
| 106 | 120 | return this.getClass().getSimpleName(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ | |||
| 16 | 16 | public final class JustCopy implements IntegerCODEC, SkippableIntegerCODEC { | |
| 17 | 17 | ||
| 18 | 18 | @Override | |
| 19 | - public void compress(int[] in, IntWrapper inpos, int inlength, | ||
| 19 | + public void headlessCompress(int[] in, IntWrapper inpos, int inlength, | ||
| 20 | 20 | int[] out, IntWrapper outpos) { | |
| 21 | 21 | System.arraycopy(in, inpos.get(), out, outpos.get(), inlength); | |
| 22 | 22 | inpos.add(inlength); | |
@@ -26,9 +26,7 @@ public void compress(int[] in, IntWrapper inpos, int inlength, | |||
| 26 | 26 | @Override | |
| 27 | 27 | public void uncompress(int[] in, IntWrapper inpos, int inlength, | |
| 28 | 28 | int[] out, IntWrapper outpos) { | |
| 29 | - System.arraycopy(in, inpos.get(), out, outpos.get(), inlength); | ||
| 30 | - inpos.add(inlength); | ||
| 31 | - outpos.add(inlength); | ||
| 29 | + headlessUncompress(in,inpos,inlength,out,outpos,inlength); | ||
| 32 | 30 | } | |
| 33 | 31 | ||
| 34 | 32 | @Override | |
@@ -37,12 +35,18 @@ public String toString() { | |||
| 37 | 35 | } | |
| 38 | 36 | ||
| 39 | 37 | @Override | |
| 40 | - public void uncompress(int[] in, IntWrapper inpos, int inlength, | ||
| 38 | + public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, | ||
| 41 | 39 | int[] out, IntWrapper outpos, int num) { | |
| 42 | 40 | System.arraycopy(in, inpos.get(), out, outpos.get(), num); | |
| 43 | 41 | inpos.add(num); | |
| 44 | 42 | outpos.add(num); | |
| 45 | 43 | ||
| 46 | 44 | } | |
| 47 | 45 | ||
| 46 | + @Override | ||
| 47 | + public void compress(int[] in, IntWrapper inpos, int inlength, | ||
| 48 | + int[] out, IntWrapper outpos) { | ||
| 49 | + headlessCompress(in,inpos,inlength,out,outpos); | ||
| 50 | + } | ||
| 51 | + | ||
| 48 | 52 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,10 +30,15 @@ private static byte extract7bits(int i, long val) { | |||
| 30 | 30 | private static byte extract7bitsmaskless(int i, long val) { | |
| 31 | 31 | return (byte) ((val >> (7 * i))); | |
| 32 | 32 | } | |
| 33 | - | ||
| 34 | 33 | @Override | |
| 35 | 34 | public void compress(int[] in, IntWrapper inpos, int inlength, int[] out, | |
| 36 | 35 | IntWrapper outpos) { | |
| 36 | + headlessCompress(in, inpos, inlength, out, outpos); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public void headlessCompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 41 | + IntWrapper outpos) { | ||
| 37 | 42 | if (inlength == 0) | |
| 38 | 43 | return; | |
| 39 | 44 | ByteBuffer buf = ByteBuffer.allocateDirect(inlength * 8); | |
@@ -176,7 +181,7 @@ public String toString() { | |||
| 176 | 181 | } | |
| 177 | 182 | ||
| 178 | 183 | @Override | |
| 179 | - public void uncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 184 | + public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 180 | 185 | IntWrapper outpos, int num) { | |
| 181 | 186 | int s = 0; | |
| 182 | 187 | int val = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ public class Kamikaze implements SkippableIntegerCODEC { | |||
| 17 | 17 | private int BLOCK_SIZE = 128; | |
| 18 | 18 | ||
| 19 | 19 | @Override | |
| 20 | - public void compress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 20 | + public void headlessCompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 21 | 21 | IntWrapper outpos) { | |
| 22 | 22 | ||
| 23 | 23 | inlength = inlength / BLOCK_SIZE * BLOCK_SIZE; | |
@@ -30,7 +30,7 @@ public void compress(int[] in, IntWrapper inpos, int inlength, int[] out, | |||
| 30 | 30 | } | |
| 31 | 31 | ||
| 32 | 32 | @Override | |
| 33 | - public void uncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 33 | + public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 34 | 34 | IntWrapper outpos, int num) { | |
| 35 | 35 | ||
| 36 | 36 | num = num / BLOCK_SIZE * BLOCK_SIZE; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,22 +36,22 @@ public SkippableComposition(SkippableIntegerCODEC f1, | |||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | @Override | |
| 39 | - public void compress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 39 | + public void headlessCompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 40 | 40 | IntWrapper outpos) { | |
| 41 | 41 | int init = inpos.get(); | |
| 42 | - F1.compress(in, inpos, inlength, out, outpos); | ||
| 42 | + F1.headlessCompress(in, inpos, inlength, out, outpos); | ||
| 43 | 43 | inlength -= inpos.get() - init; | |
| 44 | - F2.compress(in, inpos, inlength, out, outpos); | ||
| 44 | + F2.headlessCompress(in, inpos, inlength, out, outpos); | ||
| 45 | 45 | } | |
| 46 | 46 | ||
| 47 | 47 | @Override | |
| 48 | - public void uncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 48 | + public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 49 | 49 | IntWrapper outpos, int num) { | |
| 50 | 50 | int init = inpos.get(); | |
| 51 | - F1.uncompress(in, inpos, inlength, out, outpos, num); | ||
| 51 | + F1.headlessUncompress(in, inpos, inlength, out, outpos, num); | ||
| 52 | 52 | inlength -= inpos.get() - init; | |
| 53 | 53 | num -= outpos.get(); | |
| 54 | - F2.uncompress(in, inpos, inlength, out, outpos, num); | ||
| 54 | + F2.headlessUncompress(in, inpos, inlength, out, outpos, num); | ||
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | 57 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,7 +86,7 @@ public SkippableFastPFOR() { | |||
| 86 | 86 | * @see IntegerCODEC#compress(int[], IntWrapper, int, int[], IntWrapper) | |
| 87 | 87 | */ | |
| 88 | 88 | @Override | |
| 89 | - public void compress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 89 | + public void headlessCompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 90 | 90 | IntWrapper outpos) { | |
| 91 | 91 | inlength = Util.floorBy(inlength, 128); | |
| 92 | 92 | if (inlength == 0) | |
@@ -220,7 +220,7 @@ private void encodePage(int[] in, IntWrapper inpos, int thissize, | |||
| 220 | 220 | * @see IntegerCODEC#compress(int[], IntWrapper, int, int[], IntWrapper) | |
| 221 | 221 | */ | |
| 222 | 222 | @Override | |
| 223 | - public void uncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 223 | + public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 224 | 224 | IntWrapper outpos, int num) { | |
| 225 | 225 | if (inlength == 0) | |
| 226 | 226 | return; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,7 @@ public interface SkippableIntegerCODEC { | |||
| 41 | 41 | * @param outpos | |
| 42 | 42 | * where to write in the output array | |
| 43 | 43 | */ | |
| 44 | - public void compress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 44 | + public void headlessCompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 45 | 45 | IntWrapper outpos); | |
| 46 | 46 | ||
| 47 | 47 | /** | |
@@ -63,7 +63,7 @@ public void compress(int[] in, IntWrapper inpos, int inlength, int[] out, | |||
| 63 | 63 | * @param num | |
| 64 | 64 | * number of integers we want to decode, the actual number of integers decoded can be less | |
| 65 | 65 | */ | |
| 66 | - public void uncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 66 | + public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 67 | 67 | IntWrapper outpos, int num); | |
| 68 | 68 | ||
| 69 | 69 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,7 @@ public SkippableNewPFD() { | |||
| 52 | 52 | } | |
| 53 | 53 | ||
| 54 | 54 | @Override | |
| 55 | - public void compress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 55 | + public void headlessCompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 56 | 56 | IntWrapper outpos) { | |
| 57 | 57 | inlength = inlength / BlockSize * BlockSize; | |
| 58 | 58 | ||
@@ -131,7 +131,7 @@ private void encodePage(int[] in, IntWrapper inpos, int thissize, | |||
| 131 | 131 | } | |
| 132 | 132 | ||
| 133 | 133 | @Override | |
| 134 | - public void uncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 134 | + public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 135 | 135 | IntWrapper outpos, int num) { | |
| 136 | 136 | int mynvalue = num / BlockSize * BlockSize; | |
| 137 | 137 | int finalout = outpos.get() + mynvalue; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,7 @@ public SkippableOptPFD() { | |||
| 51 | 51 | } | |
| 52 | 52 | ||
| 53 | 53 | @Override | |
| 54 | - public void compress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 54 | + public void headlessCompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 55 | 55 | IntWrapper outpos) { | |
| 56 | 56 | // Util.assertTrue(inpos.get()+inlength <= in.length); | |
| 57 | 57 | inlength = inlength / BlockSize * BlockSize; | |
@@ -148,7 +148,7 @@ private void encodePage(int[] in, IntWrapper inpos, int thissize, | |||
| 148 | 148 | } | |
| 149 | 149 | ||
| 150 | 150 | @Override | |
| 151 | - public void uncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 151 | + public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, int[] out, | ||
| 152 | 152 | IntWrapper outpos, int num) { | |
| 153 | 153 | // Util.assertTrue(inpos.get()+inlength <= in.length); | |
| 154 | 154 | int mynvalue = num / BlockSize * BlockSize; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments