public ByteBuffer compress(ByteBuffer input, int elementCount, int unitLength, int maxCompressedLength) { DeltaOfDeltaBlockEncoder blockEncoder = new DeltaOfDeltaBlockEncoder(unitLength); int count = 0; //TODO: create header in advanced ByteBuffer output = ByteBuffer.Allocate(maxCompressedLength); while (elementCount > 0 && count < maxCompressedLength) { int blockSize = Math.Min(elementCount * unitLength, DEFAULT_BLOCK_SIZE); long[] compressed = blockEncoder.compress(input, blockSize); //write blockSize+data output.WriteInt(compressed.Length * sizeof(long) * 8); foreach (long l in compressed) { output.WriteLong(l); } count += sizeof(int) * 8 + compressed.Length * sizeof(long) * 8; elementCount -= blockSize / unitLength; } return(output); }
public int compress(AbstractVector input, int elementCount, int unitLength, int maxCompressedLength, ByteBuffer output) { DeltaOfDeltaBlockEncoder blockEncoder = new DeltaOfDeltaBlockEncoder(unitLength); int count = 0; int dataCount = input.rows(); int dataIndex = 0; ByteBuffer dataBufer = ByteBuffer.Allocate(DEFAULT_BLOCK_SIZE); dataBufer.order(output.isLittleEndian); int partial = 0, elementNum = 0; while (dataCount > dataIndex) { int readBytes = input.serialize(dataIndex, partial, dataCount - dataIndex, out elementNum, out partial, dataBufer); dataIndex += elementNum; while (readBytes > 0) { int blockSize = Math.Min(readBytes, DEFAULT_BLOCK_SIZE); long[] compressed = blockEncoder.compress(dataBufer, blockSize); //write blockSize+data output.WriteInt(compressed.Length * sizeof(long)); foreach (long l in compressed) { if (output.remain() < sizeof(long)) { output.reserve(output.Capacity * 2); } output.WriteLong(l); } count += sizeof(int) + compressed.Length * sizeof(long); readBytes -= blockSize; dataBufer.Clear(); } } return(count); }