Class SentinelInt32Set
A native int hash-based set where one value is reserved to mean "EMPTY" internally. The space overhead is fairly low as there is only one power-of-two sized int[] to hold the values. The set is re-hashed when adding a value that would make it >= 75% full. Consider extending and over-riding Hash(int) if the values might be poor hash keys; Lucene docids should be fine. The internal fields are exposed publicly to enable more efficient use at the expense of better O-O principles.
To iterate over the integers held in this set, simply use code like this:SentinelIntSet set = ...
foreach (int v in set.keys)
{
if (v == set.EmptyVal)
continue;
//use v...
}
NOTE: This was SentinelIntSet in Lucene
If you need to extend this class and subclass it, keep in mind that constructor calls a private "ClearInternal" method and not virtual Clear. So if you need to do some specific initialization in subclass constructor, call your own private method with whatever custom initialization you need.
Note
This API is for internal purposes only and might change in incompatible ways in the next release.
Inherited Members
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
public class SentinelInt32Set
Constructors
SentinelInt32Set(int, int)
A native int hash-based set where one value is reserved to mean "EMPTY" internally. The space overhead is fairly low as there is only one power-of-two sized int[] to hold the values. The set is re-hashed when adding a value that would make it >= 75% full. Consider extending and over-riding Hash(int) if the values might be poor hash keys; Lucene docids should be fine. The internal fields are exposed publicly to enable more efficient use at the expense of better O-O principles.
To iterate over the integers held in this set, simply use code like this:SentinelIntSet set = ...
foreach (int v in set.keys)
{
if (v == set.EmptyVal)
continue;
//use v...
}
NOTE: This was SentinelIntSet in Lucene
If you need to extend this class and subclass it, keep in mind that constructor calls a private "ClearInternal" method and not virtual Clear. So if you need to do some specific initialization in subclass constructor, call your own private method with whatever custom initialization you need.
Note
This API is for internal purposes only and might change in incompatible ways in the next release.
Declaration
public SentinelInt32Set(int size, int emptyVal)
Parameters
Type | Name | Description |
---|---|---|
int | size | The minimum number of elements this set should be able to hold without rehashing (i.e. the slots are guaranteed not to change). |
int | emptyVal | The integer value to use for EMPTY. |
Properties
Count
The number of integers in this set.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
EmptyVal
A native int hash-based set where one value is reserved to mean "EMPTY" internally. The space overhead is fairly low as there is only one power-of-two sized int[] to hold the values. The set is re-hashed when adding a value that would make it >= 75% full. Consider extending and over-riding Hash(int) if the values might be poor hash keys; Lucene docids should be fine. The internal fields are exposed publicly to enable more efficient use at the expense of better O-O principles.
To iterate over the integers held in this set, simply use code like this:SentinelIntSet set = ...
foreach (int v in set.keys)
{
if (v == set.EmptyVal)
continue;
//use v...
}
NOTE: This was SentinelIntSet in Lucene
If you need to extend this class and subclass it, keep in mind that constructor calls a private "ClearInternal" method and not virtual Clear. So if you need to do some specific initialization in subclass constructor, call your own private method with whatever custom initialization you need.
Note
This API is for internal purposes only and might change in incompatible ways in the next release.
Declaration
public int EmptyVal { get; }
Property Value
Type | Description |
---|---|
int |
Keys
A power-of-2 over-sized array holding the integers in the set along with empty values.
Declaration
public int[] Keys { get; set; }
Property Value
Type | Description |
---|---|
int[] |
RehashCount
The count at which a rehash should be done.
Declaration
public int RehashCount { get; set; }
Property Value
Type | Description |
---|---|
int |
Methods
Clear()
NOTE: When overriding this method, be aware that the constructor of this class calls a private method and not this virtual method. So if you need to override the behavior during the initialization, call your own private method from the constructor with whatever custom behavior you need.
Declaration
public virtual void Clear()
Exists(int)
Does this set contain the specified integer?
Declaration
public virtual bool Exists(int key)
Parameters
Type | Name | Description |
---|---|---|
int | key |
Returns
Type | Description |
---|---|
bool |
Find(int)
(internal) Returns the slot for this key, or -slot-1 if not found.
Declaration
public virtual int Find(int key)
Parameters
Type | Name | Description |
---|---|---|
int | key |
Returns
Type | Description |
---|---|
int |
GetSlot(int)
(internal) Returns the slot for this key.
Declaration
public virtual int GetSlot(int key)
Parameters
Type | Name | Description |
---|---|---|
int | key |
Returns
Type | Description |
---|---|
int |
Hash(int)
(internal) Return the hash for the key. The default implementation just returns the key, which is not appropriate for general purpose use.
Declaration
public virtual int Hash(int key)
Parameters
Type | Name | Description |
---|---|---|
int | key |
Returns
Type | Description |
---|---|
int |
Put(int)
Puts this integer (key) in the set, and returns the slot index it was added to. It rehashes if adding it would make the set more than 75% full.
Declaration
public virtual int Put(int key)
Parameters
Type | Name | Description |
---|---|---|
int | key |
Returns
Type | Description |
---|---|
int |
Rehash()
(internal) Rehashes by doubling key (int[]) and filling with the old values.
Declaration
public virtual void Rehash()