public void uncompress(sbyte[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { int p = inpos.get(); int finalp = inpos.get() + inlength; int tmpoutpos = outpos.get(); for (int v = 0; p < finalp; @out[tmpoutpos++] = v) { v = @in[p] & 0x7F; if (@in[p] < 0) { p += 1; continue; } v = ((@in[p + 1] & 0x7F) << 7) | v; if (@in[p + 1] < 0) { p += 2; continue; } v = ((@in[p + 2] & 0x7F) << 14) | v; if (@in[p + 2] < 0) { p += 3; continue; } v = ((@in[p + 3] & 0x7F) << 21) | v; if (@in[p + 3] < 0) { p += 4; continue; } v = ((@in[p + 4] & 0x7F) << 28) | v; p += 5; } outpos.set(tmpoutpos); inpos.add(p); }
/** * Compress data in blocks of BLOCK_SIZE integers (if fewer than BLOCK_SIZE integers * are provided, nothing is done). * * @see IntegerCODEC#compress(int[], IntWrapper, int, int[], IntWrapper) */ public void headlessCompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { inlength = Util.greatestMultiple(inlength, BLOCK_SIZE); int finalinpos = inpos.get() + inlength; while (inpos.get() != finalinpos) { int thissize = Math.Min(pageSize, finalinpos - inpos.get()); encodePage(@in, inpos, thissize, @out, outpos); } }
public void uncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { if (inlength == 0) { return; } int outlength = @in[inpos.get()]; inpos.increment(); headlessUncompress(@in, inpos, inlength, @out, outpos, outlength); }
private void decodePage(int[] @in, IntWrapper inpos, int[] @out, IntWrapper outpos, int thissize) { int initpos = inpos.get(); int wheremeta = @in[inpos.get()]; inpos.increment(); int inexcept = initpos + wheremeta; int bytesize = @in[inexcept++]; byteContainer.clear(); //byteContainer.asIntBuffer().put(@in, inexcept, (bytesize + 3) / 4); //Port note: I've collapsed the code here byteContainer.put(@in, inexcept, (bytesize + 3) / 4); byteContainer._ms.Position = 0; inexcept += (bytesize + 3) / 4; int bitmap = @in[inexcept++]; for (int k = 2; k <= 32; ++k) { if ((bitmap & (1 << (k - 1))) != 0) { int size = @in[inexcept++]; int roundedup = Util .greatestMultiple(size + 31, 32); if (dataTobePacked[k].Length < roundedup) { dataTobePacked[k] = new int[roundedup]; } if (inexcept + roundedup / 32 * k <= @in.Length) { int j = 0; for (; j < size; j += 32) { BitPacking.fastunpack(@in, inexcept, dataTobePacked[k], j, k); inexcept += k; } int overflow = j - size; inexcept -= overflow * k / 32; } else { int j = 0; int[] buf = new int[roundedup / 32 * k]; int initinexcept = inexcept; Array.Copy(@in, inexcept, buf, 0, @in.Length - inexcept); for (; j < size; j += 32) { BitPacking.fastunpack(buf, inexcept - initinexcept, dataTobePacked[k], j, k); inexcept += k; } int overflow = j - size; inexcept -= overflow * k / 32; } } } Arrays.fill(dataPointers, 0); int tmpoutpos = outpos.get(); int tmpinpos = inpos.get(); for (int run = 0, run_end = thissize / BLOCK_SIZE; run < run_end; ++run, tmpoutpos += BLOCK_SIZE) { int b = byteContainer.get(); int cexcept = byteContainer.get() & 0xFF; for (int k = 0; k < BLOCK_SIZE; k += 32) { BitPacking.fastunpack(@in, tmpinpos, @out, tmpoutpos + k, b); tmpinpos += b; } if (cexcept > 0) { int maxbits = byteContainer.get(); int index = maxbits - b; if (index == 1) { for (int k = 0; k < cexcept; ++k) { int pos = byteContainer.get() & 0xFF; @out[pos + tmpoutpos] |= 1 << b; } } else { for (int k = 0; k < cexcept; ++k) { int pos = byteContainer.get() & 0xFF; int exceptvalue = dataTobePacked[index][dataPointers[index]++]; @out[pos + tmpoutpos] |= exceptvalue << b; } } } } outpos.set(tmpoutpos); inpos.set(inexcept); }
/** * Uncompress data in blocks of integers. In this particular case, * the inlength parameter is ignored: it is deduced from the compressed * data. * * @see IntegerCODEC#compress(int[], IntWrapper, int, int[], IntWrapper) */ public void headlessUncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos, int mynvalue) { if (inlength == 0) { return; } mynvalue = Util.greatestMultiple(mynvalue, BLOCK_SIZE); int finalout = outpos.get() + mynvalue; while (outpos.get() != finalout) { int thissize = Math.Min(pageSize, finalout - outpos.get()); decodePage(@in, inpos, @out, outpos, thissize); } }
private void encodePage(int[] @in, IntWrapper inpos, int thissize, int[] @out, IntWrapper outpos) { int headerpos = outpos.get(); outpos.increment(); int tmpoutpos = outpos.get(); // Clear working area. Arrays.fill(dataPointers, 0); byteContainer.clear(); int tmpinpos = inpos.get(); for (int finalinpos = tmpinpos + thissize - BLOCK_SIZE; tmpinpos <= finalinpos; tmpinpos += BLOCK_SIZE) { getBestBFromData(@in, tmpinpos); int tmpbestb = bestbbestcexceptmaxb[0]; byteContainer.put((sbyte)bestbbestcexceptmaxb[0]); byteContainer.put((sbyte)bestbbestcexceptmaxb[1]); if (bestbbestcexceptmaxb[1] > 0) { byteContainer.put((sbyte)bestbbestcexceptmaxb[2]); int index = bestbbestcexceptmaxb[2] - bestbbestcexceptmaxb[0]; if (dataPointers[index] + bestbbestcexceptmaxb[1] >= dataTobePacked[index].Length) { int newsize = 2 * (dataPointers[index] + bestbbestcexceptmaxb[1]); // make sure it is a multiple of 32 newsize = Util .greatestMultiple(newsize + 31, 32); dataTobePacked[index] = Arrays.copyOf( dataTobePacked[index], newsize); } for (int k = 0; k < BLOCK_SIZE; ++k) { if ((int)((uint)@in[k + tmpinpos] >> bestbbestcexceptmaxb[0]) != 0) { // we have an exception byteContainer.put((sbyte)k); dataTobePacked[index][dataPointers[index]++] = (int)((uint)@in[k + tmpinpos] >> tmpbestb); } } } for (int k = 0; k < BLOCK_SIZE; k += 32) { BitPacking.fastpack(@in, tmpinpos + k, @out, tmpoutpos, tmpbestb); tmpoutpos += tmpbestb; } } inpos.set(tmpinpos); @out[headerpos] = tmpoutpos - headerpos; int bytesize = byteContainer.position(); while ((byteContainer.position() & 3) != 0) { byteContainer.put((sbyte)0); } @out[tmpoutpos++] = bytesize; int howmanyints = byteContainer.position() / 4; byteContainer.flip(); byteContainer.asIntBuffer().get(@out, tmpoutpos, howmanyints); tmpoutpos += howmanyints; int bitmap = 0; for (int k = 2; k <= 32; ++k) { if (dataPointers[k] != 0) { bitmap |= (1 << (k - 1)); } } @out[tmpoutpos++] = bitmap; for (int k = 2; k <= 32; ++k) { if (dataPointers[k] != 0) { @out[tmpoutpos++] = dataPointers[k];// size int j = 0; for (; j < dataPointers[k]; j += 32) { BitPacking.fastpack(dataTobePacked[k], j, @out, tmpoutpos, k); tmpoutpos += k; } int overflow = j - dataPointers[k]; tmpoutpos -= overflow * k / 32; } } outpos.set(tmpoutpos); }
public void uncompress(int[] inBuf, IntWrapper inPos, int inLen, int[] outBuf, IntWrapper outPos) { DeltaZigzagEncoding.Decoder ctx = new DeltaZigzagEncoding.Decoder(0); int ip = inPos.get(); int op = outPos.get(); int vbcNum = 0, vbcShift = 24; // Varialbe Byte Context. int inPosLast = ip + inLen; while (ip < inPosLast) { // Fetch a byte value. int n = (int)((uint)inBuf[ip] >> vbcShift) & 0xFF; if (vbcShift > 0) { vbcShift -= 8; } else { vbcShift = 24; ip++; } // Decode variable byte and delta+zigzag. vbcNum = (vbcNum << 7) + (n & 0x7F); if ((n & 0x80) == 0) { outBuf[op++] = ctx.decodeInt(vbcNum); vbcNum = 0; } } outPos.set(op); inPos.set(inPosLast); }
public void headlessCompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { int i_inpos = inpos.get(); int i_outpos = outpos.get(); int finalin = i_inpos + inlength; while (i_inpos < finalin) { int inoffset = compressblock(@out, i_outpos++, @in, i_inpos, inlength); if (inoffset == -1) { throw new Exception("Too big a number"); } i_inpos += inoffset; inlength -= inoffset; } inpos.set(i_inpos); outpos.set(i_outpos); }
public void headlessCompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { int tmpoutpos = outpos.get(); int currentPos = inpos.get(); int finalin = currentPos + inlength; outer: while (currentPos < finalin - 28) { int selector = 0; mainloop: for (; selector < 8;) { int res = 0; int compressedNum = codeNum[selector]; int b = bitLength[selector]; int max = 1 << b; int i = 0; for (; i < compressedNum; i++) { if (max <= @in[currentPos + i]) { selector++; goto mainloop; } res = (res << b) + @in[currentPos + i]; } res |= selector << 28; @out[tmpoutpos++] = res; currentPos += compressedNum; goto outer; } const int selector2 = 8; if (@in[currentPos] >= 1 << bitLength[selector2]) { throw new Exception("Too big a number"); } @out[tmpoutpos++] = @in[currentPos++] | (selector2 << 28); } outer2: while (currentPos < finalin) { int selector3 = 0; mainloop: for (; selector3 < 8;) { int res = 0; int compressedNum = codeNum[selector3]; if (finalin <= currentPos + compressedNum - 1) { compressedNum = finalin - currentPos; } int b = bitLength[selector3]; int max = 1 << b; int i = 0; for (; i < compressedNum; i++) { if (max <= @in[currentPos + i]) { selector3++; goto mainloop; } res = (res << b) + @in[currentPos + i]; } if (compressedNum != codeNum[selector3]) { res <<= (codeNum[selector3] - compressedNum) * b; } res |= selector3 << 28; @out[tmpoutpos++] = res; currentPos += compressedNum; goto outer2; } const int selector4 = 8; if (@in[currentPos] >= 1 << bitLength[selector4]) { throw new Exception("Too big a number"); } @out[tmpoutpos++] = @in[currentPos++] | (selector4 << 28); } inpos.set(currentPos); outpos.set(tmpoutpos); }
public void headlessUncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos, int outlength) { int currentPos = outpos.get(); int tmpinpos = inpos.get(); int finalout = currentPos + outlength; while (currentPos < finalout - 28) { int val = @in[tmpinpos++]; int header = (int)((uint)val >> 28); switch (header) { case 0: { // number : 28, bitwidth : 1 @out[currentPos++] = (int)((uint)(val << 4) >> 31); @out[currentPos++] = (int)((uint)(val << 5) >> 31); @out[currentPos++] = (int)((uint)(val << 6) >> 31); @out[currentPos++] = (int)((uint)(val << 7) >> 31); @out[currentPos++] = (int)((uint)(val << 8) >> 31); @out[currentPos++] = (int)((uint)(val << 9) >> 31); @out[currentPos++] = (int)((uint)(val << 10) >> 31); @out[currentPos++] = (int)((uint)(val << 11) >> 31); @out[currentPos++] = (int)((uint)(val << 12) >> 31); @out[currentPos++] = (int)((uint)(val << 13) >> 31); // 10 @out[currentPos++] = (int)((uint)(val << 14) >> 31); @out[currentPos++] = (int)((uint)(val << 15) >> 31); @out[currentPos++] = (int)((uint)(val << 16) >> 31); @out[currentPos++] = (int)((uint)(val << 17) >> 31); @out[currentPos++] = (int)((uint)(val << 18) >> 31); @out[currentPos++] = (int)((uint)(val << 19) >> 31); @out[currentPos++] = (int)((uint)(val << 20) >> 31); @out[currentPos++] = (int)((uint)(val << 21) >> 31); @out[currentPos++] = (int)((uint)(val << 22) >> 31); @out[currentPos++] = (int)((uint)(val << 23) >> 31); // 20 @out[currentPos++] = (int)((uint)(val << 24) >> 31); @out[currentPos++] = (int)((uint)(val << 25) >> 31); @out[currentPos++] = (int)((uint)(val << 26) >> 31); @out[currentPos++] = (int)((uint)(val << 27) >> 31); @out[currentPos++] = (int)((uint)(val << 28) >> 31); @out[currentPos++] = (int)((uint)(val << 29) >> 31); @out[currentPos++] = (int)((uint)(val << 30) >> 31); @out[currentPos++] = (int)((uint)(val << 31) >> 31); break; } case 1: { // number : 14, bitwidth : 2 @out[currentPos++] = (int)((uint)(val << 4) >> 30); @out[currentPos++] = (int)((uint)(val << 6) >> 30); @out[currentPos++] = (int)((uint)(val << 8) >> 30); @out[currentPos++] = (int)((uint)(val << 10) >> 30); @out[currentPos++] = (int)((uint)(val << 12) >> 30); @out[currentPos++] = (int)((uint)(val << 14) >> 30); @out[currentPos++] = (int)((uint)(val << 16) >> 30); @out[currentPos++] = (int)((uint)(val << 18) >> 30); @out[currentPos++] = (int)((uint)(val << 20) >> 30); @out[currentPos++] = (int)((uint)(val << 22) >> 30); // 10 @out[currentPos++] = (int)((uint)(val << 24) >> 30); @out[currentPos++] = (int)((uint)(val << 26) >> 30); @out[currentPos++] = (int)((uint)(val << 28) >> 30); @out[currentPos++] = (int)((uint)(val << 30) >> 30); break; } case 2: { // number : 9, bitwidth : 3 @out[currentPos++] = (int)((uint)(val << 5) >> 29); @out[currentPos++] = (int)((uint)(val << 8) >> 29); @out[currentPos++] = (int)((uint)(val << 11) >> 29); @out[currentPos++] = (int)((uint)(val << 14) >> 29); @out[currentPos++] = (int)((uint)(val << 17) >> 29); @out[currentPos++] = (int)((uint)(val << 20) >> 29); @out[currentPos++] = (int)((uint)(val << 23) >> 29); @out[currentPos++] = (int)((uint)(val << 26) >> 29); @out[currentPos++] = (int)((uint)(val << 29) >> 29); break; } case 3: { // number : 7, bitwidth : 4 @out[currentPos++] = (int)((uint)(val << 4) >> 28); @out[currentPos++] = (int)((uint)(val << 8) >> 28); @out[currentPos++] = (int)((uint)(val << 12) >> 28); @out[currentPos++] = (int)((uint)(val << 16) >> 28); @out[currentPos++] = (int)((uint)(val << 20) >> 28); @out[currentPos++] = (int)((uint)(val << 24) >> 28); @out[currentPos++] = (int)((uint)(val << 28) >> 28); break; } case 4: { // number : 5, bitwidth : 5 @out[currentPos++] = (int)((uint)(val << 7) >> 27); @out[currentPos++] = (int)((uint)(val << 12) >> 27); @out[currentPos++] = (int)((uint)(val << 17) >> 27); @out[currentPos++] = (int)((uint)(val << 22) >> 27); @out[currentPos++] = (int)((uint)(val << 27) >> 27); break; } case 5: { // number : 4, bitwidth : 7 @out[currentPos++] = (int)((uint)(val << 4) >> 25); @out[currentPos++] = (int)((uint)(val << 11) >> 25); @out[currentPos++] = (int)((uint)(val << 18) >> 25); @out[currentPos++] = (int)((uint)(val << 25) >> 25); break; } case 6: { // number : 3, bitwidth : 9 @out[currentPos++] = (int)((uint)(val << 5) >> 23); @out[currentPos++] = (int)((uint)(val << 14) >> 23); @out[currentPos++] = (int)((uint)(val << 23) >> 23); break; } case 7: { // number : 2, bitwidth : 14 @out[currentPos++] = (int)((uint)(val << 4) >> 18); @out[currentPos++] = (int)((uint)(val << 18) >> 18); break; } case 8: { // number : 1, bitwidth : 28 @out[currentPos++] = (int)((uint)(val << 4) >> 4); break; } default: { throw new Exception("shouldn't happen: limited to 28-bit integers"); } } } while (currentPos < finalout) { int val = @in[tmpinpos++]; int header = (int)((uint)val >> 28); switch (header) { case 0: { // number : 28, bitwidth : 1 int howmany = finalout - currentPos; for (int k = 0; k < howmany; ++k) { @out[currentPos++] = (int)((uint)(val << (k + 4)) >> 31); } break; } case 1: { // number : 14, bitwidth : 2 int howmany = finalout - currentPos < 14 ? finalout - currentPos : 14; for (int k = 0; k < howmany; ++k) { @out[currentPos++] = (int)((uint)(val << (2 * k + 4)) >> 30); } break; } case 2: { // number : 9, bitwidth : 3 int howmany = finalout - currentPos < 9 ? finalout - currentPos : 9; for (int k = 0; k < howmany; ++k) { @out[currentPos++] = (int)((uint)(val << (3 * k + 5)) >> 29); } break; } case 3: { // number : 7, bitwidth : 4 int howmany = finalout - currentPos < 7 ? finalout - currentPos : 7; for (int k = 0; k < howmany; ++k) { @out[currentPos++] = (int)((uint)(val << (4 * k + 4)) >> 28); } break; } case 4: { // number : 5, bitwidth : 5 int howmany = finalout - currentPos < 5 ? finalout - currentPos : 5; for (int k = 0; k < howmany; ++k) { @out[currentPos++] = (int)((uint)(val << (5 * k + 7)) >> 27); } break; } case 5: { // number : 4, bitwidth : 7 int howmany = finalout - currentPos < 4 ? finalout - currentPos : 4; for (int k = 0; k < howmany; ++k) { @out[currentPos++] = (int)((uint)(val << (7 * k + 4)) >> 25); } break; } case 6: { // number : 3, bitwidth : 9 int howmany = finalout - currentPos < 3 ? finalout - currentPos : 3; for (int k = 0; k < howmany; ++k) { @out[currentPos++] = (int)((uint)(val << (9 * k + 5)) >> 23); } break; } case 7: { // number : 2, bitwidth : 14 int howmany = finalout - currentPos < 2 ? finalout - currentPos : 2; for (int k = 0; k < howmany; ++k) { @out[currentPos++] = (int)((uint)(val << (14 * k + 4)) >> 18); } break; } case 8: { // number : 1, bitwidth : 28 @out[currentPos++] = (int)((uint)(val << 4) >> 4); break; } default: { throw new Exception("shouldn't happen"); } } } outpos.set(currentPos); inpos.set(tmpinpos); }
public void compress(int[] @in, IntWrapper inpos, int inlength, sbyte[] @out, IntWrapper outpos) { if (inlength == 0) { return; } int outpostmp = outpos.get(); for (int k = inpos.get(); k < inpos.get() + inlength; ++k) { long val = @in[k] & 0xFFFFFFFFL; // To be consistent with // unsigned integers in C/C++ if (val < (1 << 7)) { @out[outpostmp++] = (sbyte)(val | (1 << 7)); } else if (val < (1 << 14)) { @out[outpostmp++] = (sbyte)extract7bits(0, val); @out[outpostmp++] = (sbyte)(extract7bitsmaskless(1, (val)) | (1 << 7)); } else if (val < (1 << 21)) { @out[outpostmp++] = (sbyte)extract7bits(0, val); @out[outpostmp++] = (sbyte)extract7bits(1, val); @out[outpostmp++] = (sbyte)(extract7bitsmaskless(2, (val)) | (1 << 7)); } else if (val < (1 << 28)) { @out[outpostmp++] = (sbyte)extract7bits(0, val); @out[outpostmp++] = (sbyte)extract7bits(1, val); @out[outpostmp++] = (sbyte)extract7bits(2, val); @out[outpostmp++] = (sbyte)(extract7bitsmaskless(3, (val)) | (1 << 7)); } else { @out[outpostmp++] = (sbyte)extract7bits(0, val); @out[outpostmp++] = (sbyte)extract7bits(1, val); @out[outpostmp++] = (sbyte)extract7bits(2, val); @out[outpostmp++] = (sbyte)extract7bits(3, val); @out[outpostmp++] = (sbyte)(extract7bitsmaskless(4, (val)) | (1 << 7)); } } outpos.set(outpostmp); inpos.add(inlength); }
public void headlessCompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { if (inlength == 0) { return; } ByteBuffer buf = ByteBuffer.allocateDirect(inlength * 8); buf.order(ByteOrder.LITTLE_ENDIAN); for (int k = inpos.get(); k < inpos.get() + inlength; ++k) { long val = @in[k] & 0xFFFFFFFFL; // To be consistent with // unsigned integers in C/C++ if (val < (1 << 7)) { buf.put((sbyte)(val | (1 << 7))); } else if (val < (1 << 14)) { buf.put((sbyte)extract7bits(0, val)); buf.put((sbyte)(extract7bitsmaskless(1, (val)) | (1 << 7))); } else if (val < (1 << 21)) { buf.put((sbyte)extract7bits(0, val)); buf.put((sbyte)extract7bits(1, val)); buf.put((sbyte)(extract7bitsmaskless(2, (val)) | (1 << 7))); } else if (val < (1 << 28)) { buf.put((sbyte)extract7bits(0, val)); buf.put((sbyte)extract7bits(1, val)); buf.put((sbyte)extract7bits(2, val)); buf.put((sbyte)(extract7bitsmaskless(3, (val)) | (1 << 7))); } else { buf.put((sbyte)extract7bits(0, val)); buf.put((sbyte)extract7bits(1, val)); buf.put((sbyte)extract7bits(2, val)); buf.put((sbyte)extract7bits(3, val)); buf.put((sbyte)(extract7bitsmaskless(4, (val)) | (1 << 7))); } } while (buf.position() % 4 != 0) { buf.put((sbyte)0); } int length = buf.position(); buf.flip(); IntBuffer ibuf = buf.asIntBuffer(); ibuf.get(@out, outpos.get(), length / 4); outpos.add(length / 4); inpos.add(inlength); }
public void headlessUncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos, int num) { int s = 0; int val = 0; int p = inpos.get(); int tmpoutpos = outpos.get(); int finaloutpos = num + tmpoutpos; for (int v = 0, shift = 0; tmpoutpos < finaloutpos;) { val = @in[p]; int c = (int)((uint)val >> s); s += 8; p += s >> 5; s = s & 31; v += ((c & 127) << shift); if ((c & 128) == 128) { @out[tmpoutpos++] = v; v = 0; shift = 0; } else { shift += 7; } } outpos.set(tmpoutpos); inpos.set(p + (s != 0 ? 1 : 0)); }
public void uncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { int s = 0; int val = 0; int p = inpos.get(); int finalp = inpos.get() + inlength; int tmpoutpos = outpos.get(); for (int v = 0, shift = 0; p < finalp;) { val = @in[p]; int c = (sbyte)(int)((uint)val >> s); s += 8; p += s >> 5; s = s & 31; v += ((c & 127) << shift); if ((c & 128) == 128) { @out[tmpoutpos++] = v; v = 0; shift = 0; } else { shift += 7; } } outpos.set(tmpoutpos); inpos.add(inlength); }
public void headlessUncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos, int num) { Array.Copy(@in, inpos.get(), @out, outpos.get(), num); inpos.add(num); outpos.add(num); }
public void compress(int[] inBuf, IntWrapper inPos, int inLen, int[] outBuf, IntWrapper outPos) { if (inLen == 0) { return; } ByteBuffer byteBuf = ByteBuffer.allocateDirect(inLen * 5 + 3); DeltaZigzagEncoding.Encoder ctx = new DeltaZigzagEncoding.Encoder(0); // Delta+Zigzag+VariableByte encoding. int ip = inPos.get(); int inPosLast = ip + inLen; for (; ip < inPosLast; ++ip) { // Filter with delta+zigzag encoding. int n = ctx.encodeInt(inBuf[ip]); // Variable byte encoding. //PORT NOTE: The following IF statements are ported from a switch. Fall through switches are not allowed in C# int zeros = Integer.numberOfLeadingZeros(n); if (zeros < 4) { byteBuf.put((sbyte)(((int)((uint)n >> 28) & 0x7F) | 0x80)); } if (zeros < 11) { byteBuf.put((sbyte)(((int)((uint)n >> 21) & 0x7F) | 0x80)); } if (zeros < 18) { byteBuf.put((sbyte)(((int)((uint)n >> 14) & 0x7F) | 0x80)); } if (zeros < 25) { byteBuf.put((sbyte)(((int)((uint)n >> 7) & 0x7F) | 0x80)); } byteBuf.put((sbyte)((uint)n & 0x7F)); } // Padding buffer to considerable as IntBuffer. for (int i = (4 - (byteBuf.position() % 4)) % 4; i > 0; --i) { unchecked { byteBuf.put((sbyte)(0x80)); } } int outLen = byteBuf.position() / 4; byteBuf.flip(); IntBuffer intBuf = byteBuf.asIntBuffer(); /* * Console.WriteLine(String.format( * "inLen=%d pos=%d limit=%d outLen=%d outBuf.len=%d", inLen, * intBuf.position(), intBuf.limit(), outLen, outBuf.Length)); */ intBuf.get(outBuf, outPos.get(), outLen); inPos.add(inLen); outPos.add(outLen); }
public void compress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { headlessCompress(@in, inpos, inlength, @out, outpos); }
public void headlessUncompress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos, int num) { int i_inpos = inpos.get(); int i_outpos = outpos.get(); while (num > 0) { int howmany = decompressblock(@out, i_outpos, @in, i_inpos, num); num -= howmany; i_outpos += howmany; i_inpos++; } inpos.set(i_inpos); outpos.set(i_outpos); }