Show / Hide Table of Contents

    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
    System.Object
    LurchTable<TKey, TValue>
    Implements
    IDisposable
    Namespace: Lucene.Net.Support
    Assembly: Lucene.Net.dll
    Syntax
    public class LurchTable<TKey, TValue> : IDictionary<TKey, TValue>, 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 Source

    LurchTable(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

    | Improve this Doc View Source

    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

    IEqualityComparer<TKey> comparer

    The element hash generator for keys, or null to use

    | Improve this Doc View Source

    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

    IEqualityComparer<TKey> comparer

    The element hash generator for keys, or null to use

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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

    | Improve this Doc View Source

    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

    IEqualityComparer<TKey> comparer

    The element hash generator for keys, or null to use

    Properties

    | Improve this Doc View Source

    Comparer

    Retrives the key comparer being used by this instance.

    Declaration
    public IEqualityComparer<TKey> Comparer { get; }
    Property Value
    Type Description
    IEqualityComparer<TKey>
    | Improve this Doc View Source

    Count

    Gets the number of elements contained in the System.Collections.Generic.ICollection<>.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    System.Int32
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    Keys

    Gets an System.Collections.Generic.ICollection<> containing the keys of the System.Collections.Generic.IDictionary<, >.

    Declaration
    public LurchTable<TKey, TValue>.KeyCollection Keys { get; }
    Property Value
    Type Description
    LurchTable.KeyCollection<>
    | Improve this Doc View Source

    Limit

    Gets or Sets the record limit allowed in this instance.

    Declaration
    public int Limit { get; set; }
    Property Value
    Type Description
    System.Int32
    | Improve this Doc View Source

    Ordering

    Retrieves the LurchTableOrder Ordering enumeration this instance was created with.

    Declaration
    public LurchTableOrder Ordering { get; }
    Property Value
    Type Description
    LurchTableOrder
    | Improve this Doc View Source

    Values

    Gets an System.Collections.Generic.ICollection<> containing the values in the System.Collections.Generic.IDictionary<, >.

    Declaration
    public LurchTable<TKey, TValue>.ValueCollection Values { get; }
    Property Value
    Type Description
    LurchTable.ValueCollection<>

    Methods

    | Improve this Doc View Source

    Add(TKey, TValue)

    Adds an element with the provided key and value to the System.Collections.Generic.IDictionary<, >.

    Declaration
    public void Add(TKey key, TValue value)
    Parameters
    Type Name Description
    TKey key
    TValue value
    | Improve this Doc View Source

    AddOrUpdate(TKey, TValue, KeyValueUpdate<TKey, TValue>)

    Adds a key/value pair to the System.Collections.Generic.IDictionary<, > 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
    | Improve this Doc View Source

    AddOrUpdate(TKey, Func<TKey, TValue>, KeyValueUpdate<TKey, TValue>)

    Adds a key/value pair to the System.Collections.Generic.IDictionary<, > 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
    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.

    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    Clear()

    Removes all items from the System.Collections.Generic.ICollection<>.

    Declaration
    public void Clear()
    | Improve this Doc View Source

    ContainsKey(TKey)

    Determines whether the System.Collections.Generic.IDictionary<, > contains an element with the specified key.

    Declaration
    public bool ContainsKey(TKey key)
    Parameters
    Type Name Description
    TKey key
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    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
    KeyValuePair<TKey, TValue>

    The Key/Value pair removed.

    | Improve this Doc View Source

    Dispose()

    Clears references to all objects and invalidates the collection

    Declaration
    public void Dispose()
    | Improve this Doc View Source

    GetEnumerator()

    Returns an enumerator that iterates through the collection.

    Declaration
    public LurchTable<TKey, TValue>.Enumerator GetEnumerator()
    Returns
    Type Description
    LurchTable.Enumerator<>
    | Improve this Doc View Source

    GetOrAdd(TKey, TValue)

    Adds a key/value pair to the System.Collections.Generic.IDictionary<, > 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
    | Improve this Doc View Source

    GetOrAdd(TKey, Func<TKey, TValue>)

    Adds a key/value pair to the System.Collections.Generic.IDictionary<, > 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.

    Func<TKey, TValue> fnCreate

    Constructs a new value for the key.

    Returns
    Type Description
    TValue
    | Improve this Doc View Source

    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()
    | Improve this Doc View Source

    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
    KeyValuePair<TKey, TValue> value
    Returns
    Type Description
    System.Boolean

    True if the out parameter value was set.

    | Improve this Doc View Source

    Remove(TKey)

    Removes the element with the specified key from the System.Collections.Generic.IDictionary<, >.

    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 key was not found in the original System.Collections.Generic.IDictionary<, >.

    | Improve this Doc View Source

    TryAdd(TKey, TValue)

    Adds an element with the provided key and value to the System.Collections.Generic.IDictionary<, >.

    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
    | Improve this Doc View Source

    TryAdd(TKey, Func<TKey, TValue>)

    Adds an element with the provided key and value to the System.Collections.Generic.IDictionary<, > 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
    Func<TKey, TValue> fnCreate
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    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
    KeyValuePair<TKey, TValue> value
    Returns
    Type Description
    System.Boolean

    False if no item was available

    | Improve this Doc View Source

    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
    Predicate<KeyValuePair<TKey, TValue>> predicate
    KeyValuePair<TKey, TValue> value
    Returns
    Type Description
    System.Boolean

    False if no item was available

    | Improve this Doc View Source

    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<, > contains an element with the specified key; otherwise, false.

    | Improve this Doc View Source

    TryRemove(TKey, out TValue)

    Removes the element with the specified key from the System.Collections.Generic.IDictionary<, >.

    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 key was not found in the original System.Collections.Generic.IDictionary<, >.

    | Improve this Doc View Source

    TryRemove(TKey, KeyValuePredicate<TKey, TValue>)

    Removes the element with the specified key from the System.Collections.Generic.IDictionary<, > 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
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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 Source

    ItemAdded

    Event raised after an item is added to the collection

    Declaration
    public event Action<KeyValuePair<TKey, TValue>> ItemAdded
    Event Type
    Type Description
    Action<KeyValuePair<TKey, TValue>>
    | Improve this Doc View Source

    ItemRemoved

    Event raised after an item is removed from the collection

    Declaration
    public event Action<KeyValuePair<TKey, TValue>> ItemRemoved
    Event Type
    Type Description
    Action<KeyValuePair<TKey, TValue>>
    | Improve this Doc View Source

    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<>

    Implements

    IDisposable
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)