Class SentinelInt32Set
A native System.Int32 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(Int32) 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
Inheritance
Inherited Members
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
public class SentinelInt32Set
Constructors
| Improve this Doc View SourceSentinelInt32Set(Int32, Int32)
Declaration
public SentinelInt32Set(int size, int emptyVal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | size | The minimum number of elements this set should be able to hold without rehashing (i.e. the slots are guaranteed not to change). |
System.Int32 | emptyVal | The integer value to use for EMPTY. |
Properties
| Improve this Doc View SourceCount
The number of integers in this set.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
EmptyVal
Declaration
public int EmptyVal { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
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 |
---|---|
System.Int32[] |
RehashCount
The count at which a rehash should be done.
Declaration
public int RehashCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceClear()
Declaration
public virtual void Clear()
Exists(Int32)
Does this set contain the specified integer?
Declaration
public virtual bool Exists(int key)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key |
Returns
Type | Description |
---|---|
System.Boolean |
Find(Int32)
(internal) Returns the slot for this key, or -slot-1 if not found.
Declaration
public virtual int Find(int key)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key |
Returns
Type | Description |
---|---|
System.Int32 |
GetSlot(Int32)
(internal) Returns the slot for this key.
Declaration
public virtual int GetSlot(int key)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key |
Returns
Type | Description |
---|---|
System.Int32 |
Hash(Int32)
(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 |
---|---|---|
System.Int32 | key |
Returns
Type | Description |
---|---|
System.Int32 |
Put(Int32)
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 |
---|---|---|
System.Int32 | key |
Returns
Type | Description |
---|---|
System.Int32 |
Rehash()
(internal) Rehashes by doubling key (int[]) and filling with the old values.
Declaration
public virtual void Rehash()