Package org.apache.lucene.util
Class ByteBlockPool
- java.lang.Object
-
- org.apache.lucene.util.ByteBlockPool
-
public final class ByteBlockPool extends Object
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.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classByteBlockPool.AllocatorAbstract class for allocating and freeing byte blocks.static classByteBlockPool.DirectAllocatorA simpleByteBlockPool.Allocatorthat never recycles.static classByteBlockPool.DirectTrackingAllocatorA simpleByteBlockPool.Allocatorthat never recycles, but tracks how much total RAM is in use.
-
Field Summary
Fields Modifier and Type Field Description byte[]bufferbyte[][]buffersstatic intBYTE_BLOCK_MASKstatic intBYTE_BLOCK_SHIFTstatic intBYTE_BLOCK_SIZEintbyteOffsetintbyteUptostatic intFIRST_LEVEL_SIZEstatic int[]levelSizeArraystatic int[]nextLevelArray
-
Constructor Summary
Constructors Constructor Description ByteBlockPool(ByteBlockPool.Allocator allocator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intallocSlice(byte[] slice, int upto)voidcopy(BytesRef bytes)BytesRefcopyFrom(BytesRef bytes)voiddropBuffersAndReset()intnewSlice(int size)voidnextBuffer()voidreset()BytesRefsetBytesRef(BytesRef term, int textStart)voidwritePool(DataOutput out)Writes the pools content to the givenDataOutput
-
-
-
Field Detail
-
BYTE_BLOCK_SHIFT
public static final int BYTE_BLOCK_SHIFT
- See Also:
- Constant Field Values
-
BYTE_BLOCK_SIZE
public static final int BYTE_BLOCK_SIZE
- See Also:
- Constant Field Values
-
BYTE_BLOCK_MASK
public static final int BYTE_BLOCK_MASK
- See Also:
- Constant Field Values
-
buffers
public byte[][] buffers
-
byteUpto
public int byteUpto
-
buffer
public byte[] buffer
-
byteOffset
public int byteOffset
-
nextLevelArray
public static final int[] nextLevelArray
-
levelSizeArray
public static final int[] levelSizeArray
-
FIRST_LEVEL_SIZE
public static final int FIRST_LEVEL_SIZE
-
-
Constructor Detail
-
ByteBlockPool
public ByteBlockPool(ByteBlockPool.Allocator allocator)
-
-
Method Detail
-
dropBuffersAndReset
public void dropBuffersAndReset()
-
reset
public void reset()
-
nextBuffer
public void nextBuffer()
-
newSlice
public int newSlice(int size)
-
allocSlice
public int allocSlice(byte[] slice, int upto)
-
copy
public final void copy(BytesRef bytes)
-
writePool
public final void writePool(DataOutput out) throws IOException
Writes the pools content to the givenDataOutput- Throws:
IOException
-
-