|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.lucene.util.ByteBlockPool
public final class ByteBlockPool
Class that Posting and PostingVector use to write byte streams into shared fixed-size byte[] arrays. The idea is to allocate slices of increasing lengths For example, the first slice is 5 bytes, the next slice is 14, etc. We start by writing our bytes into the first 5 bytes. When we hit the end of the slice, we allocate the next slice and then write the address of the new slice into the last 4 bytes of the previous slice (the "forwarding address"). Each slice is filled with 0's initially, and we mark the end with a non-zero byte. This way the methods that are writing into the slice don't need to record its length and instead allocate a new slice once they hit a non-zero byte.
Nested Class Summary | |
---|---|
static class |
ByteBlockPool.Allocator
Abstract class for allocating and freeing byte blocks. |
static class |
ByteBlockPool.DirectAllocator
A simple ByteBlockPool.Allocator that never recycles. |
static class |
ByteBlockPool.DirectTrackingAllocator
A simple ByteBlockPool.Allocator that never recycles, but
tracks how much total RAM is in use. |
Field Summary | |
---|---|
byte[] |
buffer
Current head buffer |
byte[][] |
buffers
array of buffers currently used in the pool. |
static int |
BYTE_BLOCK_MASK
|
static int |
BYTE_BLOCK_SHIFT
|
static int |
BYTE_BLOCK_SIZE
|
int |
byteOffset
Current head offset |
int |
byteUpto
Where we are in head buffer |
static int |
FIRST_LEVEL_SIZE
The first level size for new slices |
static int[] |
LEVEL_SIZE_ARRAY
An array holding the level sizes for byte slices. |
static int[] |
NEXT_LEVEL_ARRAY
An array holding the offset into the LEVEL_SIZE_ARRAY
to quickly navigate to the next slice level. |
Constructor Summary | |
---|---|
ByteBlockPool(ByteBlockPool.Allocator allocator)
|
Method Summary | |
---|---|
int |
allocSlice(byte[] slice,
int upto)
Creates a new byte slice with the given starting size and returns the slices offset in the pool. |
void |
copy(BytesRef bytes)
Copies the given BytesRef at the current positions (
byteUpto across buffer boundaries |
BytesRef |
copyFrom(BytesRef bytes,
int offset,
int length)
Copies bytes from the pool starting at the given offset with the given length into the given BytesRef at offset 0 and returns it. |
BytesRef |
deref(BytesRef bytes)
Dereferences the byte block according to BytesRef offset. |
int |
newSlice(int size)
Allocates a new slice with the given size. |
void |
nextBuffer()
Advances the pool to its next buffer. |
void |
reset()
Resets the pool to its initial state reusing the first buffer and fills all buffers with 0 bytes before they reused or passed to ByteBlockPool.Allocator.recycleByteBlocks(byte[][], int, int) . |
void |
reset(boolean zeroFillBuffers,
boolean reuseFirst)
Expert: Resets the pool to its initial state reusing the first buffer. |
BytesRef |
setBytesRef(BytesRef term,
int textStart)
|
void |
writePool(DataOutput out)
Writes the pools content to the given DataOutput |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int BYTE_BLOCK_SHIFT
public static final int BYTE_BLOCK_SIZE
public static final int BYTE_BLOCK_MASK
public byte[][] buffers
public int byteUpto
public byte[] buffer
public int byteOffset
public static final int[] NEXT_LEVEL_ARRAY
LEVEL_SIZE_ARRAY
to quickly navigate to the next slice level.
public static final int[] LEVEL_SIZE_ARRAY
public static final int FIRST_LEVEL_SIZE
newSlice(int)
Constructor Detail |
---|
public ByteBlockPool(ByteBlockPool.Allocator allocator)
Method Detail |
---|
public void reset()
ByteBlockPool.Allocator.recycleByteBlocks(byte[][], int, int)
. Calling
nextBuffer()
is not needed after reset.
public void reset(boolean zeroFillBuffers, boolean reuseFirst)
nextBuffer()
is not needed after reset.
zeroFillBuffers
- if true
the buffers are filled with 0.
This should be set to true
if this pool is used with slices.reuseFirst
- if true
the first buffer will be reused and calling
nextBuffer()
is not needed after reset iff the
block pool was used before ie. nextBuffer()
was called before.public void nextBuffer()
reset()
call will advance the pool to
its first buffer immediately.
public int newSlice(int size)
FIRST_LEVEL_SIZE
public int allocSlice(byte[] slice, int upto)
public final BytesRef setBytesRef(BytesRef term, int textStart)
public final BytesRef deref(BytesRef bytes)
BytesRef
offset. The offset
is interpreted as the absolute offset into the ByteBlockPool
.
public final void copy(BytesRef bytes)
BytesRef
at the current positions (
byteUpto
across buffer boundaries
public final BytesRef copyFrom(BytesRef bytes, int offset, int length)
BytesRef
at offset 0 and returns it.
Note: this method allows to copy across block boundaries.
public final void writePool(DataOutput out) throws IOException
DataOutput
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |