pre-process speed: fast binary also for 90m srtm
This commit is contained in:
parent
ab621d2b2e
commit
98b3f62efb
5 changed files with 153 additions and 26 deletions
|
|
@ -9,8 +9,8 @@ public class BitCoderContext
|
|||
private int bits; // bits left in buffer
|
||||
private int b; // buffer word
|
||||
|
||||
private static final int[] vl_values = new int[4096];
|
||||
private static final int[] vl_length = new int[4096];
|
||||
public static final int[] vl_values = new int[4096];
|
||||
public static final int[] vl_length = new int[4096];
|
||||
|
||||
private static final int[] vc_values = new int[4096];
|
||||
private static final int[] vc_length = new int[4096];
|
||||
|
|
|
|||
|
|
@ -16,8 +16,11 @@ public final class MixCoderDataInputStream extends DataInputStream
|
|||
private int repCount;
|
||||
private int diffshift;
|
||||
|
||||
private int bm = 0x100;
|
||||
private int b;
|
||||
private int bits; // bits left in buffer
|
||||
private int b; // buffer word
|
||||
|
||||
private static final int[] vl_values = BitCoderContext.vl_values;
|
||||
private static final int[] vl_length = BitCoderContext.vl_length;
|
||||
|
||||
public MixCoderDataInputStream( InputStream is )
|
||||
{
|
||||
|
|
@ -40,46 +43,99 @@ public final class MixCoderDataInputStream extends DataInputStream
|
|||
|
||||
public final boolean decodeBit() throws IOException
|
||||
{
|
||||
if ( bm == 0x100 )
|
||||
{
|
||||
bm = 1;
|
||||
b = readByte();
|
||||
}
|
||||
boolean value = ( ( b & bm ) != 0 );
|
||||
bm <<= 1;
|
||||
fillBuffer();
|
||||
boolean value = ( ( b & 1 ) != 0 );
|
||||
b >>>= 1;
|
||||
bits--;
|
||||
return value;
|
||||
}
|
||||
|
||||
public final int decodeVarBits() throws IOException
|
||||
public final int decodeVarBits2() throws IOException
|
||||
{
|
||||
int range = 0;
|
||||
int value = 0;
|
||||
while (!decodeBit())
|
||||
{
|
||||
value += range + 1;
|
||||
range = 2 * range + 1;
|
||||
}
|
||||
return value + decodeBounded( range );
|
||||
return range + decodeBounded( range );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* decode an integer in the range 0..max (inclusive).
|
||||
* @see #encodeBounded
|
||||
*/
|
||||
public final int decodeBounded( int max ) throws IOException
|
||||
{
|
||||
int value = 0;
|
||||
int im = 1; // integer mask
|
||||
while (( value | im ) <= max)
|
||||
{
|
||||
if ( bm == 0x100 )
|
||||
if ( decodeBit() )
|
||||
{
|
||||
bm = 1;
|
||||
b = readByte();
|
||||
}
|
||||
if ( ( b & bm ) != 0 )
|
||||
value |= im;
|
||||
bm <<= 1;
|
||||
}
|
||||
im <<= 1;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see #encodeVarBits
|
||||
*/
|
||||
|
||||
public final int decodeVarBits() throws IOException
|
||||
{
|
||||
fillBuffer();
|
||||
int b12 = b & 0xfff;
|
||||
int len = vl_length[b12];
|
||||
if ( len <= 12 )
|
||||
{
|
||||
b >>>= len;
|
||||
bits -= len;
|
||||
return vl_values[b12]; // full value lookup
|
||||
}
|
||||
if ( len <= 23 ) // // only length lookup
|
||||
{
|
||||
int len2 = len >> 1;
|
||||
b >>>= (len2+1);
|
||||
int mask = 0xffffffff >>> ( 32 - len2 );
|
||||
mask += b & mask;
|
||||
b >>>= len2;
|
||||
bits -= len;
|
||||
return mask;
|
||||
}
|
||||
if ( (b & 0xffffff) != 0 )
|
||||
{
|
||||
// here we just know len in [25..47]
|
||||
// ( fillBuffer guarantees only 24 bits! )
|
||||
b >>>= 12;
|
||||
int len3 = 1 + (vl_length[b & 0xfff]>>1);
|
||||
b >>>= len3;
|
||||
int len2 = 11 + len3;
|
||||
bits -= len2+1;
|
||||
fillBuffer();
|
||||
int mask = 0xffffffff >>> ( 32 - len2 );
|
||||
mask += b & mask;
|
||||
b >>>= len2;
|
||||
bits -= len2;
|
||||
return mask;
|
||||
}
|
||||
return decodeVarBits2(); // no chance, use the slow one
|
||||
}
|
||||
|
||||
private void fillBuffer() throws IOException
|
||||
{
|
||||
while (bits < 24)
|
||||
{
|
||||
int nextByte = read();
|
||||
|
||||
if ( nextByte != -1 )
|
||||
{
|
||||
b |= (nextByte & 0xff) << bits;
|
||||
}
|
||||
bits += 8;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue