Package org.apache.lucene.util
Class IntBlockPool
java.lang.Object
org.apache.lucene.util.IntBlockPool
A pool for int blocks similar to
ByteBlockPool
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Abstract class for allocating and freeing int blocks.static final class
A simpleIntBlockPool.Allocator
that never recycles.static final class
AIntBlockPool.SliceReader
that can read int slices written by aIntBlockPool.SliceWriter
static class
AIntBlockPool.SliceWriter
that allows to write multiple integer slices into a givenIntBlockPool
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IntBlockPool.Allocator
int[]
Current head bufferint[][]
array of buffers currently used in the pool.private int
index into the buffers array pointing to the current buffer used as the headprivate static final int
The first level size for new slicesstatic final int
static final int
static final int
int
Current head offsetint
Pointer to the current position in head bufferprivate static final int[]
An array holding the level sizes for int slices.private static final int[]
An array holding the offset into theLEVEL_SIZE_ARRAY
to quickly navigate to the next slice level. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newIntBlockPool
with a defaultIntBlockPool.Allocator
.IntBlockPool
(IntBlockPool.Allocator allocator) Creates a newIntBlockPool
with the givenIntBlockPool.Allocator
. -
Method Summary
Modifier and TypeMethodDescriptionprivate int
allocSlice
(int[] slice, int sliceOffset) Allocates a new slice from the given offsetprivate static boolean
assertSliceBuffer
(int[] buffer) private int
newSlice
(int size) Creates a new int slice with the given starting size and returns the slices offset in the pool.void
Advances the pool to its next buffer.void
reset()
Resets the pool to its initial state reusing the first buffer.void
reset
(boolean zeroFillBuffers, boolean reuseFirst) Expert: Resets the pool to its initial state reusing the first buffer.
-
Field Details
-
INT_BLOCK_SHIFT
public static final int INT_BLOCK_SHIFT- See Also:
-
INT_BLOCK_SIZE
public static final int INT_BLOCK_SIZE- See Also:
-
INT_BLOCK_MASK
public static final int INT_BLOCK_MASK- See Also:
-
buffers
public int[][] buffersarray of buffers currently used in the pool. Buffers are allocated if needed don't modify this outside of this class -
bufferUpto
private int bufferUptoindex into the buffers array pointing to the current buffer used as the head -
intUpto
public int intUptoPointer to the current position in head buffer -
buffer
public int[] bufferCurrent head buffer -
intOffset
public int intOffsetCurrent head offset -
allocator
-
NEXT_LEVEL_ARRAY
private static final int[] NEXT_LEVEL_ARRAYAn array holding the offset into theLEVEL_SIZE_ARRAY
to quickly navigate to the next slice level. -
LEVEL_SIZE_ARRAY
private static final int[] LEVEL_SIZE_ARRAYAn array holding the level sizes for int slices. -
FIRST_LEVEL_SIZE
private static final int FIRST_LEVEL_SIZEThe first level size for new slices
-
-
Constructor Details
-
IntBlockPool
public IntBlockPool()Creates a newIntBlockPool
with a defaultIntBlockPool.Allocator
.- See Also:
-
IntBlockPool
Creates a newIntBlockPool
with the givenIntBlockPool.Allocator
.- See Also:
-
-
Method Details
-
reset
public void reset()Resets the pool to its initial state reusing the first buffer. CallingnextBuffer()
is not needed after reset. -
reset
public void reset(boolean zeroFillBuffers, boolean reuseFirst) Expert: Resets the pool to its initial state reusing the first buffer.- Parameters:
zeroFillBuffers
- iftrue
the buffers are filled with0
. This should be set totrue
if this pool is used withIntBlockPool.SliceWriter
.reuseFirst
- iftrue
the first buffer will be reused and callingnextBuffer()
is not needed after reset iff the block pool was used before ie.nextBuffer()
was called before.
-
nextBuffer
public void nextBuffer()Advances the pool to its next buffer. This method should be called once after the constructor to initialize the pool. In contrast to the constructor areset()
call will advance the pool to its first buffer immediately. -
newSlice
private int newSlice(int size) Creates a new int slice with the given starting size and returns the slices offset in the pool.- See Also:
-
assertSliceBuffer
private static boolean assertSliceBuffer(int[] buffer) -
allocSlice
private int allocSlice(int[] slice, int sliceOffset) Allocates a new slice from the given offset
-