Class LurchTable<TKey, TValue>
LurchTable stands for "Least Used Recently Concurrent Hash Table" and has definate similarities to both the .NET 4 ConcurrentDictionary as well as Java's LinkedHashMap. This gives you a thread-safe dictionary/hashtable that stores element ordering by insertion, updates, or access. In addition it can be configured to use a 'hard-limit' count of items that will automatically 'pop' the oldest item in the collection.
Inheritance
Implements
Inherited Members
Namespace: Lucene.Net.Support
Assembly: Lucene.Net.dll
Syntax
public class LurchTable<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, IDisposable
Type Parameters
Name | Description |
---|---|
TKey | The type of keys in the dictionary. |
TValue | The type of values in the dictionary. |
Constructors
| Improve this Doc View SourceLurchTable(LurchTableOrder, Int32)
Creates a LurchTable that orders items by ordering
and removes items once the specified limit
is reached.
Declaration
public LurchTable(LurchTableOrder ordering, int limit)
Parameters
Type | Name | Description |
---|---|---|
LurchTableOrder | ordering | The type of linking for the items |
System.Int32 | limit | The maximum allowable number of items, or int.MaxValue for unlimited |
LurchTable(LurchTableOrder, Int32, IEqualityComparer<TKey>)
Creates a LurchTable that orders items by ordering
and removes items once the specified limit
is reached.
Declaration
public LurchTable(LurchTableOrder ordering, int limit, IEqualityComparer<TKey> comparer)
Parameters
Type | Name | Description |
---|---|---|
LurchTableOrder | ordering | The type of linking for the items |
System.Int32 | limit | The maximum allowable number of items, or int.MaxValue for unlimited |
System.Collections.Generic.IEqualityComparer<TKey> | comparer | The element hash generator for keys, or |
LurchTable(LurchTableOrder, Int32, Int32, Int32, Int32, IEqualityComparer<TKey>)
Creates a LurchTable that orders items by ordering
and removes items once the specified limit
is reached.
Declaration
public LurchTable(LurchTableOrder ordering, int limit, int hashSize, int allocSize, int lockSize, IEqualityComparer<TKey> comparer)
Parameters
Type | Name | Description |
---|---|---|
LurchTableOrder | ordering | The type of linking for the items |
System.Int32 | limit | The maximum allowable number of items, or int.MaxValue for unlimited |
System.Int32 | hashSize | The number of hash buckets to use for the collection, usually 1/2 estimated capacity |
System.Int32 | allocSize | The number of entries to allocate at a time, usually 1/16 estimated capacity |
System.Int32 | lockSize | The number of concurrency locks to preallocate, usually 1/256 estimated capacity |
System.Collections.Generic.IEqualityComparer<TKey> | comparer | The element hash generator for keys, or |
LurchTable(Int32)
Creates a LurchTable that can store up to capacity
items efficiently.
Declaration
public LurchTable(int capacity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | capacity | The initial allowable number of items before allocation of more memory |
LurchTable(Int32, LurchTableOrder)
Creates a LurchTable that can store up to capacity
items efficiently.
Declaration
public LurchTable(int capacity, LurchTableOrder ordering)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | capacity | The initial allowable number of items before allocation of more memory |
LurchTableOrder | ordering | The type of linking for the items |
LurchTable(Int32, LurchTableOrder, IEqualityComparer<TKey>)
Creates a LurchTable that can store up to capacity
items efficiently.
Declaration
public LurchTable(int capacity, LurchTableOrder ordering, IEqualityComparer<TKey> comparer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | capacity | The initial allowable number of items before allocation of more memory |
LurchTableOrder | ordering | The type of linking for the items |
System.Collections.Generic.IEqualityComparer<TKey> | comparer | The element hash generator for keys, or |
Properties
| Improve this Doc View SourceComparer
Retrives the key comparer being used by this instance.
Declaration
public IEqualityComparer<TKey> Comparer { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEqualityComparer<TKey> |
Count
Gets the number of elements contained in the System.Collections.Generic.ICollection<T>.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Item[TKey]
Gets or sets the element with the specified key.
Declaration
public TValue this[TKey key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
TKey | key |
Property Value
Type | Description |
---|---|
TValue |
Keys
Gets an System.Collections.Generic.ICollection<T> containing the keys of the System.Collections.Generic.IDictionary<TKey, TValue>.
Declaration
public LurchTable<TKey, TValue>.KeyCollection Keys { get; }
Property Value
Type | Description |
---|---|
LurchTable.KeyCollection<> |
Limit
Gets or Sets the record limit allowed in this instance.
Declaration
public int Limit { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Ordering
Retrieves the LurchTableOrder Ordering enumeration this instance was created with.
Declaration
public LurchTableOrder Ordering { get; }
Property Value
Type | Description |
---|---|
LurchTableOrder |
Values
Gets an System.Collections.Generic.ICollection<T> containing the values in the System.Collections.Generic.IDictionary<TKey, TValue>.
Declaration
public LurchTable<TKey, TValue>.ValueCollection Values { get; }
Property Value
Type | Description |
---|---|
LurchTable.ValueCollection<> |
Methods
| Improve this Doc View SourceAdd(TKey, TValue)
Adds an element with the provided key and value to the System.Collections.Generic.IDictionary<TKey, TValue>.
Declaration
public void Add(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
TValue | value |
AddOrUpdate(TKey, TValue, KeyValueUpdate<TKey, TValue>)
Adds a key/value pair to the System.Collections.Generic.IDictionary<TKey, TValue> if the key does not already exist, or updates a key/value pair if the key already exists.
Declaration
public TValue AddOrUpdate(TKey key, TValue addValue, KeyValueUpdate<TKey, TValue> fnUpdate)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
TValue | addValue | |
KeyValueUpdate<TKey, TValue> | fnUpdate |
Returns
Type | Description |
---|---|
TValue |
AddOrUpdate(TKey, Func<TKey, TValue>, KeyValueUpdate<TKey, TValue>)
Adds a key/value pair to the System.Collections.Generic.IDictionary<TKey, TValue> if the key does not already exist, or updates a key/value pair if the key already exists.
Declaration
public TValue AddOrUpdate(TKey key, Func<TKey, TValue> fnCreate, KeyValueUpdate<TKey, TValue> fnUpdate)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
System.Func<TKey, TValue> | fnCreate | |
KeyValueUpdate<TKey, TValue> | fnUpdate |
Returns
Type | Description |
---|---|
TValue |
Remarks
Adds or modifies an element with the provided key and value. If the key does not exist in the collection, the factory method fnCreate will be called to produce the new value, if the key exists, the converter method fnUpdate will be called to create an updated value.
AddOrUpdate<T>(TKey, ref T)
Add, update, or fetche a key/value pair from the dictionary via an implementation of the CSharpTest.Net.Collections.ICreateOrUpdateValue`2 interface.
Declaration
public bool AddOrUpdate<T>(TKey key, ref T createOrUpdateValue)
where T : ICreateOrUpdateValue<TKey, TValue>
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
T | createOrUpdateValue |
Returns
Type | Description |
---|---|
System.Boolean |
Type Parameters
Name | Description |
---|---|
T |
Clear()
Removes all items from the System.Collections.Generic.ICollection<T>.
Declaration
public void Clear()
ContainsKey(TKey)
Determines whether the System.Collections.Generic.IDictionary<TKey, TValue> contains an element with the specified key.
Declaration
public bool ContainsKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key |
Returns
Type | Description |
---|---|
System.Boolean |
Dequeue()
Removes the oldest entry in the collection based on the ordering supplied to the constructor. If an item is not available a busy-wait loop is used to wait for for an item.
Declaration
public KeyValuePair<TKey, TValue> Dequeue()
Returns
Type | Description |
---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | The Key/Value pair removed. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Raised if the table is unordered |
Dispose()
Clears references to all objects and invalidates the collection
Declaration
public void Dispose()
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public LurchTable<TKey, TValue>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
LurchTable.Enumerator<> |
GetOrAdd(TKey, TValue)
Adds a key/value pair to the System.Collections.Generic.IDictionary<TKey, TValue> if the key does not already exist.
Declaration
public TValue GetOrAdd(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to add. |
TValue | value | The value to be added, if the key does not already exist. |
Returns
Type | Description |
---|---|
TValue |
GetOrAdd(TKey, Func<TKey, TValue>)
Adds a key/value pair to the System.Collections.Generic.IDictionary<TKey, TValue> if the key does not already exist.
Declaration
public TValue GetOrAdd(TKey key, Func<TKey, TValue> fnCreate)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to add. |
System.Func<TKey, TValue> | fnCreate | Constructs a new value for the key. |
Returns
Type | Description |
---|---|
TValue |
Initialize()
WARNING: not thread-safe, reinitializes all internal structures. Use Clear() for a thread-safe delete all. If you have externally provided exclusive access this method may be used to more efficiently clear the collection.
Declaration
public void Initialize()
Peek(out KeyValuePair<TKey, TValue>)
Retrieves the oldest entry in the collection based on the ordering supplied to the constructor.
Declaration
public bool Peek(out KeyValuePair<TKey, TValue> value)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | value |
Returns
Type | Description |
---|---|
System.Boolean | True if the out parameter value was set. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Raised if the table is unordered |
Remove(TKey)
Removes the element with the specified key from the System.Collections.Generic.IDictionary<TKey, TValue>.
Declaration
public bool Remove(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to remove. |
Returns
Type | Description |
---|---|
System.Boolean | true if the element is successfully removed; otherwise, false. This method also returns false if |
TryAdd(TKey, TValue)
Adds an element with the provided key and value to the System.Collections.Generic.IDictionary<TKey, TValue>.
Declaration
public bool TryAdd(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The object to use as the key of the element to add. |
TValue | value | The object to use as the value of the element to add. |
Returns
Type | Description |
---|---|
System.Boolean |
TryAdd(TKey, Func<TKey, TValue>)
Adds an element with the provided key and value to the System.Collections.Generic.IDictionary<TKey, TValue> by calling the provided factory method to construct the value if the key is not already present in the collection.
Declaration
public bool TryAdd(TKey key, Func<TKey, TValue> fnCreate)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
System.Func<TKey, TValue> | fnCreate |
Returns
Type | Description |
---|---|
System.Boolean |
TryDequeue(out KeyValuePair<TKey, TValue>)
Removes the oldest entry in the collection based on the ordering supplied to the constructor.
Declaration
public bool TryDequeue(out KeyValuePair<TKey, TValue> value)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | value |
Returns
Type | Description |
---|---|
System.Boolean | False if no item was available |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Raised if the table is unordered |
TryDequeue(Predicate<KeyValuePair<TKey, TValue>>, out KeyValuePair<TKey, TValue>)
Removes the oldest entry in the collection based on the ordering supplied to the constructor.
Declaration
public bool TryDequeue(Predicate<KeyValuePair<TKey, TValue>> predicate, out KeyValuePair<TKey, TValue> value)
Parameters
Type | Name | Description |
---|---|---|
System.Predicate<System.Collections.Generic.KeyValuePair<TKey, TValue>> | predicate | |
System.Collections.Generic.KeyValuePair<TKey, TValue> | value |
Returns
Type | Description |
---|---|
System.Boolean | False if no item was available |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Raised if the table is unordered |
TryGetValue(TKey, out TValue)
Gets the value associated with the specified key.
Declaration
public bool TryGetValue(TKey key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
TValue | value |
Returns
Type | Description |
---|---|
System.Boolean | true if the object that implements System.Collections.Generic.IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false. |
TryRemove(TKey, out TValue)
Removes the element with the specified key from the System.Collections.Generic.IDictionary<TKey, TValue>.
Declaration
public bool TryRemove(TKey key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to remove. |
TValue | value | The value that was removed. |
Returns
Type | Description |
---|---|
System.Boolean | true if the element is successfully removed; otherwise, false. This method also returns false if |
TryRemove(TKey, KeyValuePredicate<TKey, TValue>)
Removes the element with the specified key from the System.Collections.Generic.IDictionary<TKey, TValue> if the fnCondition predicate is null or returns true.
Declaration
public bool TryRemove(TKey key, KeyValuePredicate<TKey, TValue> fnCondition)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
KeyValuePredicate<TKey, TValue> | fnCondition |
Returns
Type | Description |
---|---|
System.Boolean |
TryRemove<T>(TKey, ref T)
Conditionally removes a key/value pair from the dictionary via an implementation of the CSharpTest.Net.Collections.IRemoveValue`2 interface.
Declaration
public bool TryRemove<T>(TKey key, ref T removeValue)
where T : IRemoveValue<TKey, TValue>
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
T | removeValue |
Returns
Type | Description |
---|---|
System.Boolean |
Type Parameters
Name | Description |
---|---|
T |
TryUpdate(TKey, TValue)
Updates an element with the provided key to the value if it exists.
Declaration
public bool TryUpdate(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The object to use as the key of the element to update. |
TValue | value | The new value for the key if found. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the key provided was found and updated to the value. |
TryUpdate(TKey, TValue, TValue)
Updates an element with the provided key to the value if it exists.
Declaration
public bool TryUpdate(TKey key, TValue value, TValue comparisonValue)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The object to use as the key of the element to update. |
TValue | value | The new value for the key if found. |
TValue | comparisonValue | The value that is compared to the value of the element with key. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the key provided was found and updated to the value. |
TryUpdate(TKey, KeyValueUpdate<TKey, TValue>)
Modify the value associated with the result of the provided update method as an atomic operation, Allows for reading/writing a single record within the syncronization lock.
Declaration
public bool TryUpdate(TKey key, KeyValueUpdate<TKey, TValue> fnUpdate)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
KeyValueUpdate<TKey, TValue> | fnUpdate |
Returns
Type | Description |
---|---|
System.Boolean |
Events
| Improve this Doc View SourceItemAdded
Event raised after an item is added to the collection
Declaration
public event Action<KeyValuePair<TKey, TValue>> ItemAdded
Event Type
Type | Description |
---|---|
System.Action<System.Collections.Generic.KeyValuePair<TKey, TValue>> |
ItemRemoved
Event raised after an item is removed from the collection
Declaration
public event Action<KeyValuePair<TKey, TValue>> ItemRemoved
Event Type
Type | Description |
---|---|
System.Action<System.Collections.Generic.KeyValuePair<TKey, TValue>> |
ItemUpdated
Event raised after an item is updated in the collection
Declaration
public event LurchTable<TKey, TValue>.ItemUpdatedMethod ItemUpdated
Event Type
Type | Description |
---|---|
LurchTable.ItemUpdatedMethod<> |
Explicit Interface Implementations
| Improve this Doc View SourceICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue>)
Declaration
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | item |
ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue>)
Declaration
bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | item |
Returns
Type | Description |
---|---|
System.Boolean |
ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[], Int32)
Declaration
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue>[] | array | |
System.Int32 | arrayIndex |
ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly
Declaration
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly { get; }
Returns
Type | Description |
---|---|
System.Boolean |
ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue>)
Declaration
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue> | item |
Returns
Type | Description |
---|---|
System.Boolean |
IDictionary<TKey, TValue>.Keys
Declaration
[Obsolete]
ICollection<TKey> IDictionary<TKey, TValue>.Keys { get; }
Returns
Type | Description |
---|---|
System.Collections.Generic.ICollection<TKey> |
IDictionary<TKey, TValue>.Values
Declaration
[Obsolete]
ICollection<TValue> IDictionary<TKey, TValue>.Values { get; }
Returns
Type | Description |
---|---|
System.Collections.Generic.ICollection<TValue> |
IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
Declaration
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey, TValue>> |
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |