Package org.apache.lucene.util
Class IntBlockPool
- java.lang.Object
-
- org.apache.lucene.util.IntBlockPool
-
public final class IntBlockPool extends java.lang.ObjectA pool for int blocks similar toByteBlockPool
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIntBlockPool.AllocatorAbstract class for allocating and freeing int blocks.static classIntBlockPool.DirectAllocatorA simpleIntBlockPool.Allocatorthat never recycles.static classIntBlockPool.SliceReaderAIntBlockPool.SliceReaderthat can read int slices written by aIntBlockPool.SliceWriterstatic classIntBlockPool.SliceWriterAIntBlockPool.SliceWriterthat allows to write multiple integer slices into a givenIntBlockPool.
-
Field Summary
Fields Modifier and Type Field Description private IntBlockPool.Allocatorallocatorint[]bufferCurrent head bufferint[][]buffersarray of buffers currently used in the pool.private intbufferUptoindex into the buffers array pointing to the current buffer used as the headprivate static intFIRST_LEVEL_SIZEThe first level size for new slicesstatic intINT_BLOCK_MASKstatic intINT_BLOCK_SHIFTstatic intINT_BLOCK_SIZEintintOffsetCurrent head offsetintintUptoPointer to the current position in head bufferprivate static int[]LEVEL_SIZE_ARRAYAn array holding the level sizes for int slices.private static int[]NEXT_LEVEL_ARRAYAn array holding the offset into theLEVEL_SIZE_ARRAYto quickly navigate to the next slice level.
-
Constructor Summary
Constructors Constructor Description IntBlockPool()Creates a newIntBlockPoolwith a defaultIntBlockPool.Allocator.IntBlockPool(IntBlockPool.Allocator allocator)Creates a newIntBlockPoolwith the givenIntBlockPool.Allocator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private intallocSlice(int[] slice, int sliceOffset)Allocates a new slice from the given offsetprivate static booleanassertSliceBuffer(int[] buffer)private intnewSlice(int size)Creates a new int slice with the given starting size and returns the slices offset in the pool.voidnextBuffer()Advances the pool to its next buffer.voidreset()Resets the pool to its initial state reusing the first buffer.voidreset(boolean zeroFillBuffers, boolean reuseFirst)Expert: Resets the pool to its initial state reusing the first buffer.
-
-
-
Field Detail
-
INT_BLOCK_SHIFT
public static final int INT_BLOCK_SHIFT
- See Also:
- Constant Field Values
-
INT_BLOCK_SIZE
public static final int INT_BLOCK_SIZE
- See Also:
- Constant Field Values
-
INT_BLOCK_MASK
public static final int INT_BLOCK_MASK
- See Also:
- Constant Field Values
-
buffers
public int[][] buffers
array of buffers currently used in the pool. Buffers are allocated if needed don't modify this outside of this class
-
bufferUpto
private int bufferUpto
index into the buffers array pointing to the current buffer used as the head
-
intUpto
public int intUpto
Pointer to the current position in head buffer
-
buffer
public int[] buffer
Current head buffer
-
intOffset
public int intOffset
Current head offset
-
allocator
private final IntBlockPool.Allocator allocator
-
NEXT_LEVEL_ARRAY
private static final int[] NEXT_LEVEL_ARRAY
An array holding the offset into theLEVEL_SIZE_ARRAYto quickly navigate to the next slice level.
-
LEVEL_SIZE_ARRAY
private static final int[] LEVEL_SIZE_ARRAY
An array holding the level sizes for int slices.
-
FIRST_LEVEL_SIZE
private static final int FIRST_LEVEL_SIZE
The first level size for new slices
-
-
Constructor Detail
-
IntBlockPool
public IntBlockPool()
Creates a newIntBlockPoolwith a defaultIntBlockPool.Allocator.- See Also:
nextBuffer()
-
IntBlockPool
public IntBlockPool(IntBlockPool.Allocator allocator)
Creates a newIntBlockPoolwith the givenIntBlockPool.Allocator.- See Also:
nextBuffer()
-
-
Method Detail
-
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- iftruethe buffers are filled with 0. This should be set totrueif this pool is used withIntBlockPool.SliceWriter.reuseFirst- iftruethe 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:
IntBlockPool.SliceReader
-
assertSliceBuffer
private static boolean assertSliceBuffer(int[] buffer)
-
allocSlice
private int allocSlice(int[] slice, int sliceOffset)Allocates a new slice from the given offset
-
-