public class DebugOutputBitStream extends OutputBitStream
This class can be used to wrap an output bit stream. The semantics of the resulting write operations is unchanged, but each operation will be logged.
To simplify the output, some operations have a simplified representation. In particular:
flush()
;
position()
;
close()
;
avail, buffer, DEFAULT_BUFFER_SIZE, DELTA, fileChannel, free, GAMMA, MAX_PRECOMPUTED, os, pos, position, repositionableStream, SHIFTED_GAMMA, wrapping, ZETA_3
Constructor and Description |
---|
DebugOutputBitStream(OutputBitStream obs)
Creates a new debug output bit stream wrapping a given output bit stream and logging on standard error.
|
DebugOutputBitStream(OutputBitStream obs,
PrintStream pw)
Creates a new debug output bit stream wrapping a given output bit stream and logging on a given writer.
|
Modifier and Type | Method and Description |
---|---|
int |
align()
Aligns the stream.
|
void |
close()
Closes the bit stream.
|
void |
flush()
Flushes the bit stream.
|
void |
position(long position)
Sets this stream bit position, if it is based on a
RepositionableStream or on a FileChannel . |
long |
write(byte[] bits,
long len)
Writes a sequence of bits.
|
int |
writeBit(boolean bit)
Writes a bit.
|
int |
writeBit(int bit)
Writes a bit.
|
int |
writeDelta(int x)
Writes a natural number in δ coding.
|
int |
writeGamma(int x)
Writes a natural number in γ coding.
|
int |
writeGolomb(int x,
int b)
Writes a natural number in Golomb coding.
|
int |
writeGolomb(int x,
int b,
int log2b)
Writes a natural number in Golomb coding.
|
int |
writeInt(int x,
int len)
Writes a fixed number of bits from an integer.
|
int |
writeLong(long x,
int len)
Writes a fixed number of bits from a long.
|
int |
writeLongDelta(long x)
Writes a long natural number in δ coding.
|
int |
writeLongGamma(long x)
Writes a long natural number in γ coding.
|
long |
writeLongGolomb(long x,
long b)
Writes a long natural number in Golomb coding.
|
long |
writeLongGolomb(long x,
long b,
int log2b)
Writes a long natural number in Golomb coding.
|
int |
writeLongMinimalBinary(long x,
long b)
Writes a long natural number in a limited range using a minimal binary coding.
|
int |
writeLongMinimalBinary(long x,
long b,
int log2b)
Writes a long natural number in a limited range using a minimal binary coding.
|
int |
writeLongNibble(long x)
Writes a long natural number in variable-length nibble coding.
|
long |
writeLongSkewedGolomb(long x,
long b)
Writes a long natural number in skewed Golomb coding.
|
long |
writeLongUnary(long x)
Writes a long natural number in unary coding.
|
int |
writeLongZeta(long x,
int k)
Writes a long natural number in ζ coding.
|
int |
writeMinimalBinary(int x,
int b)
Writes a natural number in a limited range using a minimal binary coding.
|
int |
writeMinimalBinary(int x,
int b,
int log2b)
Writes a natural number in a limited range using a minimal binary coding.
|
int |
writeNibble(int x)
Writes a natural number in variable-length nibble coding.
|
int |
writeSkewedGolomb(int x,
int b)
Writes a natural number in skewed Golomb coding.
|
int |
writeUnary(int x)
Writes a natural number in unary coding.
|
int |
writeZeta(int x,
int k)
Writes a natural number in ζ coding.
|
long |
writtenBits()
Returns the number of bits written to this bit stream.
|
void |
writtenBits(long writtenBits)
Sets the number of bits written to this bit stream.
|
write, write, writeByteOffset, writeLongShiftedGamma, writeShiftedGamma
public DebugOutputBitStream(OutputBitStream obs, PrintStream pw)
obs
- the output bit stream to wrap.pw
- a print stream that will receive the logging data.public DebugOutputBitStream(OutputBitStream obs)
obs
- the output bit stream to wrap.public void flush() throws IOException
OutputBitStream
This method will align the stream, write the bit buffer, empty the
byte buffer and delegate to the OutputStream.flush()
method of
the underlying output stream.
This method is provided so that users of this class can easily wrap
repositionable streams (for instance, file-based streams, which can be
repositioned using the underlying FileChannel
).
It is guaranteed that after calling this method the underlying stream can be repositioned, and that the next write to the underlying output stream will start with the content of the first write method called afterwards.
flush
in interface Flushable
flush
in class OutputBitStream
IOException
public void close() throws IOException
OutputBitStream
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputBitStream
IOException
public long writtenBits()
OutputBitStream
writtenBits
in class OutputBitStream
public void writtenBits(long writtenBits)
OutputBitStream
This method is provided so that, for instance, the
user can reset via writtenBits(0)
the written-bits count
after a OutputBitStream.flush()
.
writtenBits
in class OutputBitStream
writtenBits
- the new value for the number of bits written so far.public int align() throws IOException
OutputBitStream
align
in class OutputBitStream
IOException
public void position(long position) throws IOException
OutputBitStream
RepositionableStream
or on a FileChannel
.
Given an underlying stream that implements RepositionableStream
or that can provide a FileChannel
via the getChannel()
method,
a call to this method has the same semantics of a OutputBitStream.flush()
,
followed by a call to position(position / 8)
on
the byte stream. Currently there is no clean, working way of supporting
out-of-byte-boundary positioning.
position
in class OutputBitStream
position
- the new position expressed as a bit offset; it must be byte-aligned.IOException
FileChannel.position(long)
public long write(byte[] bits, long len) throws IOException
OutputBitStream
write
in class OutputBitStream
bits
- a vector containing the bits to be written.len
- a bit length.len
).IOException
public int writeBit(boolean bit) throws IOException
OutputBitStream
writeBit
in class OutputBitStream
bit
- a bit.IOException
public int writeBit(int bit) throws IOException
OutputBitStream
writeBit
in class OutputBitStream
bit
- a bit.IOException
public int writeInt(int x, int len) throws IOException
OutputBitStream
writeInt
in class OutputBitStream
x
- an integer.len
- a bit length; this many lower bits of the first argument will be written
(the most significant bit first).len
).IOException
public int writeLong(long x, int len) throws IOException
OutputBitStream
writeLong
in class OutputBitStream
x
- a long.len
- a bit length; this many lower bits of the first argument will be written
(the most significant bit first).len
).IOException
public int writeUnary(int x) throws IOException
OutputBitStream
The unary coding of a natural number n is given by 0n1.
writeUnary
in class OutputBitStream
x
- a natural number.IOException
public long writeLongUnary(long x) throws IOException
OutputBitStream
writeLongUnary
in class OutputBitStream
x
- a long natural number.IOException
OutputBitStream.writeUnary(int)
public int writeGamma(int x) throws IOException
OutputBitStream
The γ coding of a positive number of k bits is obtained writing k-1 in unary, followed by the lower k-1 bits of the number. The coding of a natural number is obtained by adding one and coding.
writeGamma
in class OutputBitStream
x
- a natural number.IOException
public int writeLongGamma(long x) throws IOException
OutputBitStream
writeLongGamma
in class OutputBitStream
x
- a long natural number.IOException
OutputBitStream.writeGamma(int)
public int writeDelta(int x) throws IOException
OutputBitStream
writeDelta
in class OutputBitStream
x
- a natural number.IOException
public int writeLongDelta(long x) throws IOException
OutputBitStream
writeLongDelta
in class OutputBitStream
x
- a long natural number.IOException
OutputBitStream.writeDelta(int)
public int writeMinimalBinary(int x, int b) throws IOException
OutputBitStream
A minimal binary code is an optimal code for the uniform distribution. This method uses an optimal code in which shorter words are assigned to smaller integers.
writeMinimalBinary
in class OutputBitStream
x
- a natural number.b
- a strict upper bound for x
.IOException
public int writeMinimalBinary(int x, int b, int log2b) throws IOException
OutputBitStream
OutputBitStream.writeMinimalBinary(int,int)
because it does not
have to compute log2b
.writeMinimalBinary
in class OutputBitStream
x
- a natural number.b
- a strict upper bound for x
.log2b
- the floor of the base-2 logarithm of the bound.IOException
OutputBitStream.writeMinimalBinary(int, int)
public int writeLongMinimalBinary(long x, long b) throws IOException
OutputBitStream
writeLongMinimalBinary
in class OutputBitStream
x
- a natural number.b
- a strict upper bound for x
.IOException
OutputBitStream.writeMinimalBinary(int, int)
public int writeLongMinimalBinary(long x, long b, int log2b) throws IOException
OutputBitStream
OutputBitStream.writeLongMinimalBinary(long,long)
because it does not
have to compute log2b
.writeLongMinimalBinary
in class OutputBitStream
x
- a long natural number.b
- a strict upper bound for x
.log2b
- the floor of the base-2 logarithm of the bound.IOException
OutputBitStream.writeMinimalBinary(int, int)
public int writeGolomb(int x, int b) throws IOException
OutputBitStream
Golomb coding with modulo b writes a natural number x as the quotient of the division of x and b in unary, followed by the remainder in minimal binary code.
This method implements also the case in which b
is 0: in this case,
the argument x
may only be zero, and nothing will be written.
writeGolomb
in class OutputBitStream
x
- a natural number.b
- the modulus for the coding.IOException
public int writeGolomb(int x, int b, int log2b) throws IOException
OutputBitStream
OutputBitStream.writeGolomb(int,int)
because it does not
have to compute log2b
.writeGolomb
in class OutputBitStream
x
- a natural number.b
- the modulus for the coding.log2b
- the floor of the base-2 logarithm of the coding modulus (it is irrelevant when b
is zero).IOException
OutputBitStream.writeGolomb(int, int)
public long writeLongGolomb(long x, long b) throws IOException
OutputBitStream
writeLongGolomb
in class OutputBitStream
x
- a long natural number.b
- the modulus for the coding.IOException
OutputBitStream.writeGolomb(int, int)
public long writeLongGolomb(long x, long b, int log2b) throws IOException
OutputBitStream
OutputBitStream.writeLongGolomb(long,long)
because it does not
have to compute log2b
.writeLongGolomb
in class OutputBitStream
x
- a long natural number.b
- the modulus for the coding.log2b
- the floor of the base-2 logarithm of the coding modulus (it is irrelevant when b
is zero).IOException
OutputBitStream.writeGolomb(int, int)
public int writeSkewedGolomb(int x, int b) throws IOException
OutputBitStream
This method implements also the case in which b
is 0: in this case,
the argument x
may only be zero, and nothing will be written.
writeSkewedGolomb
in class OutputBitStream
x
- a natural number.b
- the modulus for the coding.IOException
public long writeLongSkewedGolomb(long x, long b) throws IOException
OutputBitStream
This method implements also the case in which b
is 0: in this case,
the argument x
may only be zero, and nothing will be written.
writeLongSkewedGolomb
in class OutputBitStream
x
- a long natural number.b
- the modulus for the coding.IOException
OutputBitStream.writeSkewedGolomb(int, int)
public int writeZeta(int x, int k) throws IOException
OutputBitStream
ζ coding (with modulo k) records positive numbers in the intervals [1,2k-1],[2k,2k+1-1],…,[2hk,2(h+1)k-1] by coding h in unary, followed by a minimal binary coding of the offset in the interval. The coding of a natural number is obtained by adding one and coding.
ζ codes were defined by Paolo Boldi and Sebastiano Vigna in “Codes for the World−Wide Web”, Internet Math., 2(4):405-427, 2005. The paper contains also a detailed analysis.
writeZeta
in class OutputBitStream
x
- a natural number.k
- the shrinking factor.IOException
public int writeLongZeta(long x, int k) throws IOException
OutputBitStream
writeLongZeta
in class OutputBitStream
x
- a long natural number.k
- the shrinking factor.IOException
OutputBitStream.writeZeta(int, int)
public int writeNibble(int x) throws IOException
OutputBitStream
Variable-length nibble coding records a natural number by padding its binary representation to the left using zeroes, until its length is a multiple of three. Then, the resulting string is broken in blocks of 3 bits, and each block is prefixed with a bit, which is zero for all blocks except for the last one.
writeNibble
in class OutputBitStream
x
- a natural number.IOException
public int writeLongNibble(long x) throws IOException
OutputBitStream
writeLongNibble
in class OutputBitStream
x
- a long natural number.IOException
OutputBitStream.writeNibble(int)
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.