java.lang.Object
org.apache.lucene.index.ByteSlicePool
Class that Posting and PostingVector use to write interleaved 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The first level size for new slices.static final int[]
An array holding the level sizes for byte slices.static final int[]
An array holding indexes for theLEVEL_SIZE_ARRAY
, to quickly navigate to the next slice level.final ByteBlockPool
The underlying structure consists of fixed-size blocks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
allocKnownSizeSlice
(byte[] slice, int upto) Create a new byte slice in continuation of the provided slice and return its length and offset into the pool.int
allocSlice
(byte[] slice, int upto) Creates a new byte slice in continuation of the provided slice and return its offset into the pool.int
newSlice
(int size) Allocates a new slice with the given size and level 0.
-
Field Details
-
pool
The underlying structure consists of fixed-size blocks. We overlay variable-length slices on top. Each slice is contiguous in memory, i.e. it does not straddle multiple blocks. -
LEVEL_SIZE_ARRAY
public static final int[] LEVEL_SIZE_ARRAYAn array holding the level sizes for byte slices. The first slice is 5 bytes, the second is 14, and so on. -
NEXT_LEVEL_ARRAY
public static final int[] NEXT_LEVEL_ARRAYAn array holding indexes for theLEVEL_SIZE_ARRAY
, to quickly navigate to the next slice level. These are encoded on 4 bits in the slice, so the values in this array should be less than 16.NEXT_LEVEL_ARRAY[x] == x + 1
, except for the last element, whereNEXT_LEVEL_ARRAY[x] == x
, pointing at the maximum slice size. -
FIRST_LEVEL_SIZE
public static final int FIRST_LEVEL_SIZEThe first level size for new slices.
-
-
Constructor Details
-
ByteSlicePool
-
-
Method Details
-
newSlice
public int newSlice(int size) Allocates a new slice with the given size and level 0.- Returns:
- the position where the slice starts
-
allocSlice
public int allocSlice(byte[] slice, int upto) Creates a new byte slice in continuation of the provided slice and return its offset into the pool.- Parameters:
slice
- the current sliceupto
- the offset into the current slice, which is expected to point to the last byte of the slice- Returns:
- the new slice's offset in the pool
-
allocKnownSizeSlice
public int allocKnownSizeSlice(byte[] slice, int upto) Create a new byte slice in continuation of the provided slice and return its length and offset into the pool.- Parameters:
slice
- the current sliceupto
- the offset into the current slice, which is expected to point to the last byte of the slice- Returns:
- the new slice's length on the lower 8 bits and the offset into the pool on the other 24 bits
-