Reformat whole codebase using Android Studio
This commit is contained in:
parent
d5322667d5
commit
c15913c1ab
161 changed files with 15124 additions and 18537 deletions
|
|
@ -4,23 +4,19 @@ import java.util.TreeMap;
|
|||
|
||||
import btools.util.BitCoderContext;
|
||||
|
||||
public final class StatCoderContext extends BitCoderContext
|
||||
{
|
||||
public final class StatCoderContext extends BitCoderContext {
|
||||
private static TreeMap<String, long[]> statsPerName;
|
||||
private long lastbitpos = 0;
|
||||
|
||||
|
||||
private static final int[] noisy_bits = new int[1024];
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
// noisybits lookup
|
||||
for( int i=0; i<1024; i++ )
|
||||
{
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
int p = i;
|
||||
int noisybits = 0;
|
||||
while (p > 2)
|
||||
{
|
||||
while (p > 2) {
|
||||
noisybits++;
|
||||
p >>= 1;
|
||||
}
|
||||
|
|
@ -29,29 +25,25 @@ public final class StatCoderContext extends BitCoderContext
|
|||
}
|
||||
|
||||
|
||||
public StatCoderContext( byte[] ab )
|
||||
{
|
||||
super( ab );
|
||||
public StatCoderContext(byte[] ab) {
|
||||
super(ab);
|
||||
}
|
||||
|
||||
/**
|
||||
* assign the de-/encoded bits since the last call assignBits to the given
|
||||
* name. Used for encoding statistics
|
||||
*
|
||||
*
|
||||
* @see #getBitReport
|
||||
*/
|
||||
public void assignBits( String name )
|
||||
{
|
||||
public void assignBits(String name) {
|
||||
long bitpos = getWritingBitPosition();
|
||||
if ( statsPerName == null )
|
||||
{
|
||||
if (statsPerName == null) {
|
||||
statsPerName = new TreeMap<String, long[]>();
|
||||
}
|
||||
long[] stats = statsPerName.get( name );
|
||||
if ( stats == null )
|
||||
{
|
||||
long[] stats = statsPerName.get(name);
|
||||
if (stats == null) {
|
||||
stats = new long[2];
|
||||
statsPerName.put( name, stats );
|
||||
statsPerName.put(name, stats);
|
||||
}
|
||||
stats[0] += bitpos - lastbitpos;
|
||||
stats[1] += 1;
|
||||
|
|
@ -60,20 +52,17 @@ public final class StatCoderContext extends BitCoderContext
|
|||
|
||||
/**
|
||||
* Get a textual report on the bit-statistics
|
||||
*
|
||||
*
|
||||
* @see #assignBits
|
||||
*/
|
||||
public static String getBitReport()
|
||||
{
|
||||
if ( statsPerName == null )
|
||||
{
|
||||
public static String getBitReport() {
|
||||
if (statsPerName == null) {
|
||||
return "<empty bit report>";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for ( String name : statsPerName.keySet() )
|
||||
{
|
||||
long[] stats = statsPerName.get( name );
|
||||
sb.append( name + " count=" + stats[1] + " bits=" + stats[0] + "\n" );
|
||||
for (String name : statsPerName.keySet()) {
|
||||
long[] stats = statsPerName.get(name);
|
||||
sb.append(name + " count=" + stats[1] + " bits=" + stats[0] + "\n");
|
||||
}
|
||||
statsPerName = null;
|
||||
return sb.toString();
|
||||
|
|
@ -82,76 +71,65 @@ public final class StatCoderContext extends BitCoderContext
|
|||
/**
|
||||
* encode an unsigned integer with some of of least significant bits
|
||||
* considered noisy
|
||||
*
|
||||
*
|
||||
* @see #decodeNoisyNumber
|
||||
*/
|
||||
public void encodeNoisyNumber( int value, int noisybits )
|
||||
{
|
||||
if ( value < 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "encodeVarBits expects positive value" );
|
||||
public void encodeNoisyNumber(int value, int noisybits) {
|
||||
if (value < 0) {
|
||||
throw new IllegalArgumentException("encodeVarBits expects positive value");
|
||||
}
|
||||
if ( noisybits > 0 )
|
||||
{
|
||||
int mask = 0xffffffff >>> ( 32 - noisybits );
|
||||
encodeBounded( mask, value & mask );
|
||||
if (noisybits > 0) {
|
||||
int mask = 0xffffffff >>> (32 - noisybits);
|
||||
encodeBounded(mask, value & mask);
|
||||
value >>= noisybits;
|
||||
}
|
||||
encodeVarBits( value );
|
||||
encodeVarBits(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* decode an unsigned integer with some of of least significant bits
|
||||
* considered noisy
|
||||
*
|
||||
*
|
||||
* @see #encodeNoisyNumber
|
||||
*/
|
||||
public int decodeNoisyNumber( int noisybits )
|
||||
{
|
||||
int value = decodeBits( noisybits );
|
||||
return value | ( decodeVarBits() << noisybits );
|
||||
public int decodeNoisyNumber(int noisybits) {
|
||||
int value = decodeBits(noisybits);
|
||||
return value | (decodeVarBits() << noisybits);
|
||||
}
|
||||
|
||||
/**
|
||||
* encode a signed integer with some of of least significant bits considered
|
||||
* noisy
|
||||
*
|
||||
*
|
||||
* @see #decodeNoisyDiff
|
||||
*/
|
||||
public void encodeNoisyDiff( int value, int noisybits )
|
||||
{
|
||||
if ( noisybits > 0 )
|
||||
{
|
||||
value += 1 << ( noisybits - 1 );
|
||||
int mask = 0xffffffff >>> ( 32 - noisybits );
|
||||
encodeBounded( mask, value & mask );
|
||||
public void encodeNoisyDiff(int value, int noisybits) {
|
||||
if (noisybits > 0) {
|
||||
value += 1 << (noisybits - 1);
|
||||
int mask = 0xffffffff >>> (32 - noisybits);
|
||||
encodeBounded(mask, value & mask);
|
||||
value >>= noisybits;
|
||||
}
|
||||
encodeVarBits( value < 0 ? -value : value );
|
||||
if ( value != 0 )
|
||||
{
|
||||
encodeBit( value < 0 );
|
||||
encodeVarBits(value < 0 ? -value : value);
|
||||
if (value != 0) {
|
||||
encodeBit(value < 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* decode a signed integer with some of of least significant bits considered
|
||||
* noisy
|
||||
*
|
||||
*
|
||||
* @see #encodeNoisyDiff
|
||||
*/
|
||||
public int decodeNoisyDiff( int noisybits )
|
||||
{
|
||||
public int decodeNoisyDiff(int noisybits) {
|
||||
int value = 0;
|
||||
if ( noisybits > 0 )
|
||||
{
|
||||
value = decodeBits( noisybits ) - ( 1 << ( noisybits - 1 ) );
|
||||
if (noisybits > 0) {
|
||||
value = decodeBits(noisybits) - (1 << (noisybits - 1));
|
||||
}
|
||||
int val2 = decodeVarBits() << noisybits;
|
||||
if ( val2 != 0 )
|
||||
{
|
||||
if ( decodeBit() )
|
||||
{
|
||||
if (val2 != 0) {
|
||||
if (decodeBit()) {
|
||||
val2 = -val2;
|
||||
}
|
||||
}
|
||||
|
|
@ -161,38 +139,34 @@ public final class StatCoderContext extends BitCoderContext
|
|||
/**
|
||||
* encode a signed integer with the typical range and median taken from the
|
||||
* predicted value
|
||||
*
|
||||
*
|
||||
* @see #decodePredictedValue
|
||||
*/
|
||||
public void encodePredictedValue( int value, int predictor )
|
||||
{
|
||||
public void encodePredictedValue(int value, int predictor) {
|
||||
int p = predictor < 0 ? -predictor : predictor;
|
||||
int noisybits = 0;
|
||||
|
||||
while (p > 2)
|
||||
{
|
||||
while (p > 2) {
|
||||
noisybits++;
|
||||
p >>= 1;
|
||||
}
|
||||
encodeNoisyDiff( value - predictor, noisybits );
|
||||
encodeNoisyDiff(value - predictor, noisybits);
|
||||
}
|
||||
|
||||
/**
|
||||
* decode a signed integer with the typical range and median taken from the
|
||||
* predicted value
|
||||
*
|
||||
*
|
||||
* @see #encodePredictedValue
|
||||
*/
|
||||
public int decodePredictedValue( int predictor )
|
||||
{
|
||||
public int decodePredictedValue(int predictor) {
|
||||
int p = predictor < 0 ? -predictor : predictor;
|
||||
int noisybits = 0;
|
||||
while (p > 1023)
|
||||
{
|
||||
while (p > 1023) {
|
||||
noisybits++;
|
||||
p >>= 1;
|
||||
}
|
||||
return predictor + decodeNoisyDiff( noisybits + noisy_bits[p] );
|
||||
return predictor + decodeNoisyDiff(noisybits + noisy_bits[p]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -201,30 +175,22 @@ public final class StatCoderContext extends BitCoderContext
|
|||
* number of values with the current bit being 0. This yields an number of
|
||||
* bits per value that only depends on the typical distance between subsequent
|
||||
* values and also benefits
|
||||
*
|
||||
* @param values
|
||||
* the array to encode
|
||||
* @param offset
|
||||
* position in this array where to start
|
||||
* @param subsize
|
||||
* number of values to encode
|
||||
* @param nextbit
|
||||
* bitmask with the most significant bit set to 1
|
||||
* @param mask
|
||||
* should be 0
|
||||
*
|
||||
* @param values the array to encode
|
||||
* @param offset position in this array where to start
|
||||
* @param subsize number of values to encode
|
||||
* @param nextbit bitmask with the most significant bit set to 1
|
||||
* @param mask should be 0
|
||||
*/
|
||||
public void encodeSortedArray( int[] values, int offset, int subsize, int nextbit, int mask )
|
||||
{
|
||||
if ( subsize == 1 ) // last-choice shortcut
|
||||
public void encodeSortedArray(int[] values, int offset, int subsize, int nextbit, int mask) {
|
||||
if (subsize == 1) // last-choice shortcut
|
||||
{
|
||||
while (nextbit != 0)
|
||||
{
|
||||
encodeBit( ( values[offset] & nextbit ) != 0 );
|
||||
while (nextbit != 0) {
|
||||
encodeBit((values[offset] & nextbit) != 0);
|
||||
nextbit >>= 1;
|
||||
}
|
||||
}
|
||||
if ( nextbit == 0 )
|
||||
{
|
||||
if (nextbit == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -234,71 +200,55 @@ public final class StatCoderContext extends BitCoderContext
|
|||
// count 0-bit-fraction
|
||||
int i = offset;
|
||||
int end = subsize + offset;
|
||||
for ( ; i < end; i++ )
|
||||
{
|
||||
if ( ( values[i] & mask ) != data )
|
||||
{
|
||||
for (; i < end; i++) {
|
||||
if ((values[i] & mask) != data) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int size1 = i - offset;
|
||||
int size2 = subsize - size1;
|
||||
|
||||
encodeBounded( subsize, size1 );
|
||||
if ( size1 > 0 )
|
||||
{
|
||||
encodeSortedArray( values, offset, size1, nextbit >> 1, mask );
|
||||
encodeBounded(subsize, size1);
|
||||
if (size1 > 0) {
|
||||
encodeSortedArray(values, offset, size1, nextbit >> 1, mask);
|
||||
}
|
||||
if ( size2 > 0 )
|
||||
{
|
||||
encodeSortedArray( values, i, size2, nextbit >> 1, mask );
|
||||
if (size2 > 0) {
|
||||
encodeSortedArray(values, i, size2, nextbit >> 1, mask);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param values the array to encode
|
||||
* @param offset position in this array where to start
|
||||
* @param subsize number of values to encode
|
||||
* @param nextbit bitmask with the most significant bit set to 1
|
||||
* @param value should be 0
|
||||
* @see #encodeSortedArray
|
||||
*
|
||||
* @param values
|
||||
* the array to encode
|
||||
* @param offset
|
||||
* position in this array where to start
|
||||
* @param subsize
|
||||
* number of values to encode
|
||||
* @param nextbit
|
||||
* bitmask with the most significant bit set to 1
|
||||
* @param value
|
||||
* should be 0
|
||||
*/
|
||||
public void decodeSortedArray( int[] values, int offset, int subsize, int nextbitpos, int value )
|
||||
{
|
||||
if ( subsize == 1 ) // last-choice shortcut
|
||||
public void decodeSortedArray(int[] values, int offset, int subsize, int nextbitpos, int value) {
|
||||
if (subsize == 1) // last-choice shortcut
|
||||
{
|
||||
if ( nextbitpos >= 0 )
|
||||
{
|
||||
value |= decodeBitsReverse( nextbitpos+1 );
|
||||
if (nextbitpos >= 0) {
|
||||
value |= decodeBitsReverse(nextbitpos + 1);
|
||||
}
|
||||
values[offset] = value;
|
||||
return;
|
||||
}
|
||||
if ( nextbitpos < 0 )
|
||||
{
|
||||
while (subsize-- > 0)
|
||||
{
|
||||
if (nextbitpos < 0) {
|
||||
while (subsize-- > 0) {
|
||||
values[offset++] = value;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int size1 = decodeBounded( subsize );
|
||||
int size1 = decodeBounded(subsize);
|
||||
int size2 = subsize - size1;
|
||||
|
||||
if ( size1 > 0 )
|
||||
{
|
||||
decodeSortedArray( values, offset, size1, nextbitpos-1, value );
|
||||
if (size1 > 0) {
|
||||
decodeSortedArray(values, offset, size1, nextbitpos - 1, value);
|
||||
}
|
||||
if ( size2 > 0 )
|
||||
{
|
||||
decodeSortedArray( values, offset + size1, size2, nextbitpos-1, value | (1 << nextbitpos) );
|
||||
if (size2 > 0) {
|
||||
decodeSortedArray(values, offset + size1, size2, nextbitpos - 1, value | (1 << nextbitpos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue