Class BytesRefHash
BytesRefHash is a special purpose hash-map like data-structure optimized for BytesRef instances. BytesRefHash maintains mappings of byte arrays to ids (Map<BytesRef,int>) storing the hashed bytes efficiently in continuous storage. The mapping to the id is encapsulated inside BytesRefHash and is guaranteed to be increased for each added BytesRef.
Note: The maximum capacity BytesRef instance passed to Add(BytesRef) must not be longer than BYTE_BLOCK_SIZE-2. The internal storage is limited to 2GB total byte storage.
Note
This API is for internal purposes only and might change in incompatible ways in the next release.
Implements
Inherited Members
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
public sealed class BytesRefHash : IDisposable
Constructors
BytesRefHash()
Creates a new BytesRefHash with a ByteBlockPool using a ByteBlockPool.DirectAllocator.
Declaration
public BytesRefHash()
BytesRefHash(ByteBlockPool)
Creates a new BytesRefHash
Declaration
public BytesRefHash(ByteBlockPool pool)
Parameters
Type | Name | Description |
---|---|---|
ByteBlockPool | pool |
BytesRefHash(ByteBlockPool, int, BytesStartArray)
Creates a new BytesRefHash
Declaration
public BytesRefHash(ByteBlockPool pool, int capacity, BytesRefHash.BytesStartArray bytesStartArray)
Parameters
Type | Name | Description |
---|---|---|
ByteBlockPool | pool | |
int | capacity | |
BytesRefHash.BytesStartArray | bytesStartArray |
Fields
DEFAULT_CAPACITY
BytesRefHash is a special purpose hash-map like data-structure optimized for BytesRef instances. BytesRefHash maintains mappings of byte arrays to ids (Map<BytesRef,int>) storing the hashed bytes efficiently in continuous storage. The mapping to the id is encapsulated inside BytesRefHash and is guaranteed to be increased for each added BytesRef.
Note: The maximum capacity BytesRef instance passed to Add(BytesRef) must not be longer than BYTE_BLOCK_SIZE-2. The internal storage is limited to 2GB total byte storage.
Note
This API is for internal purposes only and might change in incompatible ways in the next release.
Declaration
public const int DEFAULT_CAPACITY = 16
Field Value
Type | Description |
---|---|
int |
Properties
Count
Returns the number of BytesRef values in this BytesRefHash.
NOTE: This was size() in Lucene.Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int | The number of BytesRef values in this BytesRefHash. |
Methods
Add(BytesRef)
Adds a new BytesRef
Declaration
public int Add(BytesRef bytes)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | bytes | The bytes to hash |
Returns
Type | Description |
---|---|
int | The id the given bytes are hashed if there was no mapping for the
given bytes, otherwise |
Exceptions
Type | Condition |
---|---|
BytesRefHash.MaxBytesLengthExceededException | if the given bytes are > 2 + BYTE_BLOCK_SIZE |
AddByPoolOffset(int)
Adds a "arbitrary" int offset instead of a BytesRef term. This is used in the indexer to hold the hash for term vectors, because they do not redundantly store the byte[] term directly and instead reference the byte[] term already stored by the postings BytesRefHash. See Add(int).
Declaration
public int AddByPoolOffset(int offset)
Parameters
Type | Name | Description |
---|---|---|
int | offset |
Returns
Type | Description |
---|---|
int |
ByteStart(int)
Returns the bytesStart offset into the internally used
ByteBlockPool for the given bytesID
Declaration
public int ByteStart(int bytesID)
Parameters
Type | Name | Description |
---|---|---|
int | bytesID | The id to look up |
Returns
Type | Description |
---|---|
int | The bytesStart offset into the internally used ByteBlockPool for the given id |
Clear()
BytesRefHash is a special purpose hash-map like data-structure optimized for BytesRef instances. BytesRefHash maintains mappings of byte arrays to ids (Map<BytesRef,int>) storing the hashed bytes efficiently in continuous storage. The mapping to the id is encapsulated inside BytesRefHash and is guaranteed to be increased for each added BytesRef.
Note: The maximum capacity BytesRef instance passed to Add(BytesRef) must not be longer than BYTE_BLOCK_SIZE-2. The internal storage is limited to 2GB total byte storage.
Note
This API is for internal purposes only and might change in incompatible ways in the next release.
Declaration
public void Clear()
Clear(bool)
Declaration
public void Clear(bool resetPool)
Parameters
Type | Name | Description |
---|---|---|
bool | resetPool |
Compact()
Returns the ids array in arbitrary order. Valid ids start at offset of 0 and end at a limit of Count - 1
Note: this is a destructive operation. Clear() must be called in order to reuse this BytesRefHash instance.
Declaration
public int[] Compact()
Returns
Type | Description |
---|---|
int[] |
Dispose()
Closes the BytesRefHash and releases all internally used memory
Declaration
public void Dispose()
Find(BytesRef)
Returns the id of the given BytesRef.
Declaration
public int Find(BytesRef bytes)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | bytes | The bytes to look for |
Returns
Type | Description |
---|---|
int | The id of the given bytes, or |
Get(int, BytesRef)
Populates and returns a BytesRef with the bytes for the given bytesID.
Note: the given bytesID must be a positive integer less than the current size (Count)Declaration
public BytesRef Get(int bytesID, BytesRef @ref)
Parameters
Type | Name | Description |
---|---|---|
int | bytesID | The id |
BytesRef | ref | The BytesRef to populate |
Returns
Type | Description |
---|---|
BytesRef | The given BytesRef instance populated with the bytes for the given bytesID |
Reinit()
Reinitializes the BytesRefHash after a previous Clear() call. If Clear() has not been called previously this method has no effect.
Declaration
public void Reinit()
Sort(IComparer<BytesRef>)
Returns the values array sorted by the referenced byte values.
Note: this is a destructive operation. Clear() must be called in order to reuse this BytesRefHash instance.
Declaration
public int[] Sort(IComparer<BytesRef> comp)
Parameters
Type | Name | Description |
---|---|---|
IComparer<BytesRef> | comp | The IComparer{BytesRef} used for sorting |
Returns
Type | Description |
---|---|
int[] |