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.
Inheritance
Inherited Members
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
public sealed class ByteBlockPool
Constructors
| Improve this Doc View SourceByteBlockPool(ByteBlockPool.Allocator)
Declaration
public ByteBlockPool(ByteBlockPool.Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
ByteBlockPool.Allocator | allocator |
Fields
| Improve this Doc View SourceBYTE_BLOCK_MASK
Declaration
public static readonly int BYTE_BLOCK_MASK
Field Value
Type | Description |
---|---|
System.Int32 |
BYTE_BLOCK_SHIFT
Declaration
public static readonly int BYTE_BLOCK_SHIFT
Field Value
Type | Description |
---|---|
System.Int32 |
BYTE_BLOCK_SIZE
Declaration
public static readonly int BYTE_BLOCK_SIZE
Field Value
Type | Description |
---|---|
System.Int32 |
FIRST_LEVEL_SIZE
The first level size for new slices
Declaration
public static readonly int FIRST_LEVEL_SIZE
Field Value
Type | Description |
---|---|
System.Int32 |
See Also
| Improve this Doc View SourceLEVEL_SIZE_ARRAY
An array holding the level sizes for byte slices.
Declaration
public static readonly int[] LEVEL_SIZE_ARRAY
Field Value
Type | Description |
---|---|
System.Int32[] |
NEXT_LEVEL_ARRAY
An array holding the offset into the LEVEL_SIZE_ARRAY to quickly navigate to the next slice level.
Declaration
public static readonly int[] NEXT_LEVEL_ARRAY
Field Value
Type | Description |
---|---|
System.Int32[] |
Properties
| Improve this Doc View SourceBuffer
Current head buffer
Declaration
public byte[] Buffer { get; set; }
Property Value
Type | Description |
---|---|
System.Byte[] |
Buffers
Array of buffers currently used in the pool. Buffers are allocated if needed don't modify this outside of this class.
Declaration
public byte[][] Buffers { get; set; }
Property Value
Type | Description |
---|---|
System.Byte[][] |
ByteOffset
Current head offset
Declaration
public int ByteOffset { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
ByteUpto
Where we are in head buffer
Declaration
public int ByteUpto { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceAllocSlice(Byte[], Int32)
Creates a new byte slice with the given starting size and returns the slices offset in the pool.
Declaration
public int AllocSlice(byte[] slice, int upto)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | slice | |
System.Int32 | upto |
Returns
Type | Description |
---|---|
System.Int32 |
Append(BytesRef)
Appends the bytes in the provided BytesRef at the current position.
Declaration
public void Append(BytesRef bytes)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | bytes |
NewSlice(Int32)
Allocates a new slice with the given size.
Declaration
public int NewSlice(int size)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | size |
Returns
Type | Description |
---|---|
System.Int32 |
See Also
| Improve this Doc View SourceNextBuffer()
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 a Reset() call will advance the pool to its first buffer immediately.
Declaration
public void NextBuffer()
ReadBytes(Int64, Byte[], Int32, Int32)
Reads bytes bytes out of the pool starting at the given offset with the given
length into the given byte array at offset off
.
Note: this method allows to copy across block boundaries.
Declaration
public void ReadBytes(long offset, byte[] bytes, int off, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | offset | |
System.Byte[] | bytes | |
System.Int32 | off | |
System.Int32 | length |
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
RecycleByteBlocks(Byte[][], Int32, Int32). Calling
NextBuffer() is not needed after reset.
Declaration
public void Reset()
Reset(Boolean, Boolean)
Expert: Resets the pool to its initial state reusing the first buffer. Calling NextBuffer() is not needed after reset.
Declaration
public void Reset(bool zeroFillBuffers, bool reuseFirst)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | zeroFillBuffers | if |
System.Boolean | reuseFirst | if |
SetBytesRef(BytesRef, Int32)
Declaration
public void SetBytesRef(BytesRef term, int textStart)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | term | |
System.Int32 | textStart |