Tested with underlap of 2 for decompression. Changed cut-off to 8 or more saved bytes.

This commit is contained in:
Martin Haye 2016-12-30 07:59:26 -08:00
parent 9d04090881
commit 77e2a7c3cf
2 changed files with 33 additions and 19 deletions

View File

@ -1226,16 +1226,31 @@ class A2PackPartitions
def inputData = new byte[inLen]
System.arraycopy(inData, 0, inputData, 0, inLen)
def outputData = lx47.compress(inputData)
def uncomp = new byte[inLen]
lx47.decompress(outputData, uncomp)
assert uncomp == inputData
def savings = lz4Len - outputData.length
uncompTotal += inLen
lx47Savings += savings
lz4Total += lz4Len
lx47Total += outputData.length
println String.format("lz47 usize=%d savings=%d utot=%d lz4tot=%d lx47tot=%d total_savings=%d",
inLen, savings, uncompTotal, lz4Total, lx47Total, lx47Savings)
if (savings >= 8) {
//def uncomp = new byte[inLen]
//lx47.decompress(outputData, 0, uncomp, 0, inLen)
//assert uncomp == inputData
// Test overlapped decompression
def underlap = 2
def buf = new byte[inLen+underlap]
def initialOffset = inLen - outputData.length + underlap;
System.arraycopy(outputData, 0, buf, initialOffset, outputData.length)
lx47.decompress(buf, initialOffset, buf, 0, inLen)
def uncomp = Arrays.copyOfRange(buf, 0, inLen)
assert uncomp == inputData
uncompTotal += inLen
lx47Savings += savings
lz4Total += lz4Len
lx47Total += outputData.length
println String.format("lz47 usize=%d savings=%d utot=%d lz4tot=%d lx47tot=%d total_savings=%d",
inLen, savings, uncompTotal, lz4Total, lx47Total, lx47Savings)
}
else {
println String.format("lz47 usize=%d savings=%d SKIP", inLen, savings)
}
}
// Transform the LZ4 format to something we call "LZ4M", where the small offsets are stored

View File

@ -309,10 +309,10 @@ public class Lx47Algorithm
private int indexByte;
private int mask;
Lx47Reader(byte[] inBuf) {
Lx47Reader(byte[] inBuf, int inStart) {
buf = inBuf;
mask = 0;
inPos = 0;
inPos = inStart;
}
int readByte() {
@ -401,11 +401,11 @@ public class Lx47Algorithm
//System.out.format("OK [%d]: %s\n", debugs.size(), expect);
}
public void decompress(byte[] input_data, byte[] output_data)
public void decompress(byte[] input_data, int inStart, byte[] output_data, int outStart, int outLen)
{
int len;
Lx47Reader r = new Lx47Reader(input_data);
int outPos = 0;
Lx47Reader r = new Lx47Reader(input_data, inStart);
int outPos = outStart;
// Now decompress until done.
chkDebug("start");
@ -422,7 +422,9 @@ public class Lx47Algorithm
if (len != 254)
break;
}
if (outPos == output_data.length)
// Check for EOF at the end of each literal string
if (outPos == outStart+outLen)
break;
// Not a literal, so it's a sequence. Get len, offset, and copy.
@ -436,9 +438,6 @@ public class Lx47Algorithm
}
chkDebug("EOF");
assert outPos == output_data.length :
String.format("Len mismatch: expecting %d, got %d", output_data.length, outPos);
}
public byte[] compress(byte[] input_data) {
@ -446,7 +445,7 @@ public class Lx47Algorithm
input_data = "aaaaaaaaa".getBytes();
byte[] testComp = compressOptimal(optimize(input_data), input_data);
byte[] testDecomp = new byte[input_data.length];
decompress(testComp, testDecomp);
decompress(testComp, 0, testDecomp, 0, input_data.length);
assert Arrays.equals(input_data, testDecomp);
System.out.println("Good!");
System.exit(1);