public final class BlockPackedWriter extends Object
The sequence is divided into fixed-size blocks and for each block, the difference between each value and the minimum value of the block is encoded using as few bits as possible. Memory usage of this class is proportional to the block size. Each block has an overhead between 1 and 10 bytes to store the minimum value and the number of bits per value of the block.
Format:
byte
, first 7 bits are the
number of bits per value (bitsPerValue). If the 8th bit is 1,
then MinValue (see next) is 0, otherwise MinValue and needs to
be decoded
variable-length long
whose value
should be added to every int from the block to restore the original
values
packed ints
encoded on exactly bitsPerValue
bits per value. They are the subtraction of the original values and
MinValue
BlockPackedReaderIterator
,
BlockPackedReader
Modifier and Type | Field and Description |
---|---|
protected byte[] |
blocks |
protected boolean |
finished |
protected int |
off |
protected long |
ord |
protected DataOutput |
out |
protected long[] |
values |
Constructor and Description |
---|
BlockPackedWriter(DataOutput out,
int blockSize)
Sole constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(long l)
Append a new long.
|
void |
finish()
Flush all buffered data to disk.
|
protected void |
flush() |
long |
ord()
Return the number of values which have been added.
|
void |
reset(DataOutput out)
Reset this writer to wrap
out . |
protected void |
writeValues(int bitsRequired) |
protected DataOutput out
protected final long[] values
protected byte[] blocks
protected int off
protected long ord
protected boolean finished
public BlockPackedWriter(DataOutput out, int blockSize)
blockSize
- the number of values of a single block, must be a power of 2protected void flush() throws IOException
IOException
public void reset(DataOutput out)
out
. The block size remains unchanged.public void add(long l) throws IOException
IOException
public void finish() throws IOException
reset(DataOutput)
has
been called.IOException
public long ord()
protected final void writeValues(int bitsRequired) throws IOException
IOException
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.