Offsets with gamma.

This commit is contained in:
Martin Haye 2016-12-29 08:06:23 -08:00
parent 1d421aacf2
commit 77b55bbd14

View File

@ -45,6 +45,10 @@ public class Lx47Algorithm
return 1 + (offset > 128 ? 12 : 8) + elias_gamma_bits(len-1);
}
int count_bits2(int offset, int len) {
return 1 + (offset > 128 ? (8+elias_gamma_bits((offset-1)>>7)) : 8) + elias_gamma_bits(len-1);
}
Optimal[] optimize(byte[] input_data) {
int[] min = new int[MAX_OFFSET+1];
int[] max = new int[MAX_OFFSET+1];
@ -178,6 +182,16 @@ public class Lx47Algorithm
}
}
void write2Gbyte(int offset) {
assert offset >= 0 && offset <= 65535;
if (offset < 128)
writeByte(offset);
else {
writeByte((offset & 127) | 128);
writeEliasGamma(offset >> 7);
}
}
void writeOffset(int offset) {
write2byte(offset);
}
@ -317,6 +331,15 @@ public class Lx47Algorithm
return val;
}
int read2Gbyte() {
int val = readByte();
if ((val & 128) == 0)
return val;
val &= 127;
val |= (readEliasGamma() << 7);
return val;
}
int readOffset() {
return read2byte();
}