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.
Inheritance
Implements
Inherited Members
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
public sealed class BytesRefHash : IDisposableConstructors
| Improve this Doc View SourceBytesRefHash()
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, Int32, BytesRefHash.BytesStartArray)
Creates a new BytesRefHash
Declaration
public BytesRefHash(ByteBlockPool pool, int capacity, BytesRefHash.BytesStartArray bytesStartArray)Parameters
| Type | Name | Description | 
|---|---|---|
| ByteBlockPool | pool | |
| System.Int32 | capacity | |
| BytesRefHash.BytesStartArray | bytesStartArray | 
Fields
| Improve this Doc View SourceDEFAULT_CAPACITY
Declaration
public const int DEFAULT_CAPACITY = 16Field Value
| Type | Description | 
|---|---|
| System.Int32 | 
Properties
| Improve this Doc View SourceCount
Returns the number of BytesRef values in this BytesRefHash.
NOTE: This was size() in Lucene.
Declaration
public int Count { get; }Property Value
| Type | Description | 
|---|---|
| System.Int32 | The number of BytesRef values in this BytesRefHash. | 
Methods
| Improve this Doc View SourceAdd(BytesRef)
Adds a new BytesRef
Declaration
public int Add(BytesRef bytes)Parameters
| Type | Name | Description | 
|---|---|---|
| BytesRef | bytes | The bytes to hash | 
Returns
| Type | Description | 
|---|---|
| System.Int32 | 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(Int32)
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 Lucene.Net.Index.TermsHashPerField.Add(System.Int32).
Declaration
public int AddByPoolOffset(int offset)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Int32 | offset | 
Returns
| Type | Description | 
|---|---|
| System.Int32 | 
ByteStart(Int32)
Returns the bytesStart offset into the internally used
ByteBlockPool for the given bytesID
Declaration
public int ByteStart(int bytesID)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Int32 | bytesID | The id to look up | 
Returns
| Type | Description | 
|---|---|
| System.Int32 | The bytesStart offset into the internally used ByteBlockPool for the given id | 
Clear()
Declaration
public void Clear()Clear(Boolean)
Declaration
public void Clear(bool resetPool)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Boolean | 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 | 
|---|---|
| System.Int32[] | 
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 | 
|---|---|
| System.Int32 | The id of the given bytes, or  | 
Get(Int32, 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 | 
|---|---|---|
| System.Int32 | 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 | 
|---|---|---|
| System.Collections.Generic.IComparer<BytesRef> | comp | The IComparer{BytesRef} used for sorting | 
Returns
| Type | Description | 
|---|---|
| System.Int32[] |