public int decode( final InputBitStream ibs ) throws IOException { final int[] lengthIncrement = this.lengthIncrement; final long[] lastCodeWordPlusOne = this.lastCodeWordPlusOne; int curr = 0, l; long x; x = ibs.readLong( lengthIncrement[ curr ] ); for(;;) { if ( x < lastCodeWordPlusOne[ curr ] ) return symbol[ (int)( howManyUpToBlock[ curr ] - lastCodeWordPlusOne[ curr ] + x ) ]; l = lengthIncrement[ ++curr ]; if ( l == 1 ) x = x << 1 | ibs.readBit(); else x = x << l | ibs.readLong( l ); } } }
public int decode( final InputBitStream ibs ) throws IOException { final int[] lengthIncrement = this.lengthIncrement; final long[] lastCodeWordPlusOne = this.lastCodeWordPlusOne; int curr = 0, l; long x; x = ibs.readLong( lengthIncrement[ curr ] ); for(;;) { if ( x < lastCodeWordPlusOne[ curr ] ) return symbol[ (int)( howManyUpToBlock[ curr ] - lastCodeWordPlusOne[ curr ] + x ) ]; l = lengthIncrement[ ++curr ]; if ( l == 1 ) x = x << 1 | ibs.readBit(); else x = x << l | ibs.readLong( l ); } } }
@Override public int decode(final InputBitStream ibs) throws IOException { final int[] lengthIncrement = this.lengthIncrement; final long[] lastCodeWordPlusOne = this.lastCodeWordPlusOne; int curr = 0, l; long x; x = ibs.readLong(lengthIncrement[curr]); for(;;) { if (x < lastCodeWordPlusOne[curr]) return symbol[(int)(howManyUpToBlock[curr] - lastCodeWordPlusOne[curr] + x)]; l = lengthIncrement[++curr]; if (l == 1) x = x << 1 | ibs.readBit(); else x = x << l | ibs.readLong(l); } } }
@Override public long readLong(int len) throws IOException { final long x = ibs.readLong(len); pw.print(" {" + DebugOutputBitStream.int2Binary(x, len) + "}"); return x; }
@Override public long readLong( int len ) throws IOException { final long x = ibs.readLong( len ); pw.print( " {" + DebugOutputBitStream.int2Binary( x, len ) + "}" ); return x; }
@Override public long readLong( int len ) throws IOException { final long x = ibs.readLong( len ); pw.print( " {" + DebugOutputBitStream.int2Binary( x, len ) + "}" ); return x; }
/** Reads a long natural number in a limited range using a minimal binary coding. * * This method is faster than {@link #readLongMinimalBinary(long)} because it does not * have to compute <code>log2b</code>. * * @param b a strict upper bound. * @param log2b the floor of the base-2 logarithm of the bound. * @return the next minimally binary encoded long natural number. * @throws IllegalArgumentException if you try to read a negative number or use a nonpositive base. * @see OutputBitStream#writeMinimalBinary(int, int) */ public long readLongMinimalBinary( final long b, final int log2b ) throws IOException { if ( b < 1 ) throw new IllegalArgumentException( "The bound " + b + " is not positive" ); final long m = ( 1L << log2b + 1 ) - b; final long x = readLong( log2b ); if ( x < m ) return x; else return ( ( x << 1 ) + readBit() - m ); }
/** Reads a long natural number in a limited range using a minimal binary coding. * * This method is faster than {@link #readLongMinimalBinary(long)} because it does not * have to compute <code>log2b</code>. * * @param b a strict upper bound. * @param log2b the floor of the base-2 logarithm of the bound. * @return the next minimally binary encoded long natural number. * @throws IllegalArgumentException if you try to read a negative number or use a nonpositive base. * @see OutputBitStream#writeMinimalBinary(int, int) */ public long readLongMinimalBinary(final long b, final int log2b) throws IOException { if (b < 1) throw new IllegalArgumentException("The bound " + b + " is not positive"); final long m = (1L << log2b + 1) - b; final long x = readLong(log2b); if (x < m) return x; else return ((x << 1) + readBit() - m); }
/** Reads a long natural number in a limited range using a minimal binary coding. * * This method is faster than {@link #readLongMinimalBinary(long)} because it does not * have to compute <code>log2b</code>. * * @param b a strict upper bound. * @param log2b the floor of the base-2 logarithm of the bound. * @return the next minimally binary encoded long natural number. * @throws IllegalArgumentException if you try to read a negative number or use a nonpositive base. * @see OutputBitStream#writeMinimalBinary(int, int) */ public long readLongMinimalBinary( final long b, final int log2b ) throws IOException { if ( b < 1 ) throw new IllegalArgumentException( "The bound " + b + " is not positive" ); final long m = ( 1L << log2b + 1 ) - b; final long x = readLong( log2b ); if ( x < m ) return x; else return ( ( x << 1 ) + readBit() - m ); }
/** Reads a long natural number in δ coding. * * @return the next δ-encoded long natural number. * @see OutputBitStream#writeDelta(int) * @see #skipDeltas(int) */ public long readLongDelta() throws IOException { int preComp; if ( ( fill >= 16 || refill() >= 16 ) && ( preComp = DELTA[ current >> ( fill - 16 ) & 0xFFFF ] ) != 0 ) { readBits += preComp >> 16; fill -= preComp >> 16; return preComp & 0xFFFF; } final int msb = readGamma(); return ( ( 1L << msb ) | readLong( msb ) ) - 1; }
/** Reads a natural number in shifted γ coding. * * @return the next shifted-γ–encoded natural number. * @see OutputBitStream#writeShiftedGamma(int) * @see #skipShiftedGammas(int) */ public long readLongShiftedGamma() throws IOException { int preComp; if ( ( fill >= 16 || refill() >= 16 ) && ( preComp = SHIFTED_GAMMA[ current >> ( fill - 16 ) & 0xFFFF ] ) != 0 ) { readBits += preComp >> 16; fill -= preComp >> 16; return preComp & 0xFFFF; } final int msb = readUnary() - 1; return msb == -1 ? 0 : ( ( 1L << msb ) | readLong( msb ) ); }
/** Reads a long natural number in γ coding. * * @return the next γ-encoded long natural number. * @see OutputBitStream#writeGamma(int) * @see #skipGammas(int) */ public long readLongGamma() throws IOException { int preComp; if ((fill >= 16 || refill() >= 16) && (preComp = GAMMA[current >> (fill - 16) & 0xFFFF]) != 0) { readBits += preComp >> 16; fill -= preComp >> 16; return preComp & 0xFFFF; } final int msb = readUnary(); return ((1L << msb) | readLong(msb)) - 1; }
/** Reads a long natural number in δ coding. * * @return the next δ-encoded long natural number. * @see OutputBitStream#writeDelta(int) * @see #skipDeltas(int) */ public long readLongDelta() throws IOException { int preComp; if ( ( fill >= 16 || refill() >= 16 ) && ( preComp = DELTA[ current >> ( fill - 16 ) & 0xFFFF ] ) != 0 ) { readBits += preComp >> 16; fill -= preComp >> 16; return preComp & 0xFFFF; } final int msb = readGamma(); return ( ( 1L << msb ) | readLong( msb ) ) - 1; }
/** Reads a long natural number in γ coding. * * @return the next γ-encoded long natural number. * @see OutputBitStream#writeGamma(int) * @see #skipGammas(int) */ public long readLongGamma() throws IOException { int preComp; if ( ( fill >= 16 || refill() >= 16 ) && ( preComp = GAMMA[ current >> ( fill - 16 ) & 0xFFFF ] ) != 0 ) { readBits += preComp >> 16; fill -= preComp >> 16; return preComp & 0xFFFF; } final int msb = readUnary(); return ( ( 1L << msb ) | readLong( msb ) ) - 1; }
/** Reads a natural number in shifted γ coding. * * @return the next shifted-γ–encoded natural number. * @see OutputBitStream#writeShiftedGamma(int) * @see #skipShiftedGammas(int) */ public long readLongShiftedGamma() throws IOException { int preComp; if ((fill >= 16 || refill() >= 16) && (preComp = SHIFTED_GAMMA[current >> (fill - 16) & 0xFFFF]) != 0) { readBits += preComp >> 16; fill -= preComp >> 16; return preComp & 0xFFFF; } final int msb = readUnary() - 1; return msb == -1 ? 0 : ((1L << msb) | readLong(msb)); }
/** Reads a natural number in shifted γ coding. * * @return the next shifted-γ–encoded natural number. * @see OutputBitStream#writeShiftedGamma(int) * @see #skipShiftedGammas(int) */ public long readLongShiftedGamma() throws IOException { int preComp; if ( ( fill >= 16 || refill() >= 16 ) && ( preComp = SHIFTED_GAMMA[ current >> ( fill - 16 ) & 0xFFFF ] ) != 0 ) { readBits += preComp >> 16; fill -= preComp >> 16; return preComp & 0xFFFF; } final int msb = readUnary() - 1; return msb == -1 ? 0 : ( ( 1L << msb ) | readLong( msb ) ); }
/** Reads a long natural number in δ coding. * * @return the next δ-encoded long natural number. * @see OutputBitStream#writeDelta(int) * @see #skipDeltas(int) */ public long readLongDelta() throws IOException { int preComp; if ((fill >= 16 || refill() >= 16) && (preComp = DELTA[current >> (fill - 16) & 0xFFFF]) != 0) { readBits += preComp >> 16; fill -= preComp >> 16; return preComp & 0xFFFF; } final int msb = readGamma(); return ((1L << msb) | readLong(msb)) - 1; }
/** Reads a long natural number in γ coding. * * @return the next γ-encoded long natural number. * @see OutputBitStream#writeGamma(int) * @see #skipGammas(int) */ public long readLongGamma() throws IOException { int preComp; if ( ( fill >= 16 || refill() >= 16 ) && ( preComp = GAMMA[ current >> ( fill - 16 ) & 0xFFFF ] ) != 0 ) { readBits += preComp >> 16; fill -= preComp >> 16; return preComp & 0xFFFF; } final int msb = readUnary(); return ( ( 1L << msb ) | readLong( msb ) ) - 1; }
long compare64(InputBitStream ibs, byte[] buf, int offset, int bits) throws IOException { ibs.position(offset); long v1 = ibs.readLong(bits); long v2 = BytesUtil.getBits64(buf, offset, bits); assertTrue(v1 == v2); return v1; } }
long compare64(InputBitStream ibs, byte[] buf, int offset, int bits) throws IOException { ibs.position(offset); long v1 = ibs.readLong(bits); long v2 = BytesUtil.getBits64(buf, offset, bits); assertTrue(v1 == v2); return v1; } }