Class LruDictionary<TKey, TValue>
LruDictionary<TKey, TValue> is similar to of Java's HashMap, which has a bounded Limit; When it reaches that Limit, each time a new element is added, the least recently used (LRU) entry is removed.
Unlike the Java Lucene implementation, this one is thread safe because it is backed by the J2N.Collections.Concurrent.LurchTable<TKey, TValue>. Do note that every time an element is read from LruDictionary<TKey, TValue>, a write operation also takes place to update the element's last access time. This is because the LRU order needs to be remembered to determine which element to evict when the Limit is exceeded.
Note
This API is experimental and might change in incompatible ways in the next release.
Implements
Inherited Members
Namespace: Lucene.Net.Facet.Taxonomy
Assembly: Lucene.Net.Facet.dll
Syntax
public class LruDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable
  Type Parameters
| Name | Description | 
|---|---|
| TKey | |
| TValue | 
Constructors
LruDictionary(int)
Create a new hash map with a bounded size and with least recently used entries removed.
Declaration
public LruDictionary(int limit)
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | limit | The maximum size (in number of entries) to which the map can grow before the least recently used entries start being removed. Settinglimit to a very large value, like MaxValue
is allowed, but is less efficient than
using J2N.Collections.Generic.Dictionary<TKey, TValue> or 
Dictionary<TKey, TValue> because our class needs
to keep track of the use order (via an additional doubly-linked
list) which is not used when the map's size is always below the
maximum size.
 | 
      
LruDictionary(int, IEqualityComparer<TKey>)
Create a new hash map with a bounded size and with least recently used entries removed.
LUCENENET specific overload to allow passing in custom IEqualityComparer<T>. See LUCENENET-602.Declaration
public LruDictionary(int limit, IEqualityComparer<TKey> comparer)
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | limit | The maximum size (in number of entries) to which the map can grow before the least recently used entries start being removed. Settinglimit to a very large value, like MaxValue
is allowed, but is less efficient than
using J2N.Collections.Generic.Dictionary<TKey, TValue> or 
Dictionary<TKey, TValue> because our class needs
to keep track of the use order (via an additional doubly-linked
list) which is not used when the map's size is always below the
maximum size.
 | 
      
| IEqualityComparer<TKey> | comparer | The IEqualityComparer<T> implementation to use when comparing keys,
or   | 
      
Properties
Count
Gets the number of elements contained in the ICollection<T>.
Declaration
public virtual int Count { get; }
  Property Value
| Type | Description | 
|---|---|
| int | The number of elements contained in the ICollection<T>.  | 
      
IsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
Declaration
public virtual bool IsReadOnly { get; }
  Property Value
| Type | Description | 
|---|---|
| bool | true if the ICollection<T> is read-only; otherwise, false.  | 
      
this[TKey]
Gets or sets the element with the specified key.
Declaration
public virtual TValue this[TKey key] { get; set; }
  Parameters
| Type | Name | Description | 
|---|---|---|
| TKey | key | The key of the element to get or set.  | 
      
Property Value
| Type | Description | 
|---|---|
| TValue | The element with the specified key.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | 
  | 
      
| KeyNotFoundException | The property is retrieved and   | 
      
| NotSupportedException | The property is set and the IDictionary<TKey, TValue> is read-only.  | 
      
Keys
Gets an ICollection<T> containing the keys of the IDictionary<TKey, TValue>.
Declaration
public virtual ICollection<TKey> Keys { get; }
  Property Value
| Type | Description | 
|---|---|
| ICollection<TKey> | An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.  | 
      
Limit
Allows changing the dictionary's maximal number of elements which was defined at construction time.
Note that if the dictionary is already larger than Limit, the current implementation does not shrink it (by removing the oldest elements); Rather, the map remains in its current size as new elements are added, and will only start shrinking (until settling again on the given Limit) if existing elements are explicitly deleted.
Declaration
public virtual int Limit { get; set; }
  Property Value
| Type | Description | 
|---|---|
| int | 
Values
Gets an ICollection<T> containing the values in the IDictionary<TKey, TValue>.
Declaration
public virtual ICollection<TValue> Values { get; }
  Property Value
| Type | Description | 
|---|---|
| ICollection<TValue> | An ICollection<T> containing the values in the object that implements IDictionary<TKey, TValue>.  | 
      
Methods
Add(KeyValuePair<TKey, TValue>)
Adds an item to the ICollection<T>.
Declaration
public virtual void Add(KeyValuePair<TKey, TValue> item)
  Parameters
| Type | Name | Description | 
|---|---|---|
| KeyValuePair<TKey, TValue> | item | The object to add to the ICollection<T>.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| NotSupportedException | The ICollection<T> is read-only.  | 
      
Add(TKey, TValue)
Adds an element with the provided key and value to the IDictionary<TKey, TValue>.
Declaration
public virtual void Add(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.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | 
  | 
      
| ArgumentException | An element with the same key already exists in the IDictionary<TKey, TValue>.  | 
      
| NotSupportedException | The IDictionary<TKey, TValue> is read-only.  | 
      
Clear()
Removes all items from the ICollection<T>.
Declaration
public virtual void Clear()
  Exceptions
| Type | Condition | 
|---|---|
| NotSupportedException | The ICollection<T> is read-only.  | 
      
Contains(KeyValuePair<TKey, TValue>)
Determines whether the ICollection<T> contains a specific value.
Declaration
public virtual bool Contains(KeyValuePair<TKey, TValue> item)
  Parameters
| Type | Name | Description | 
|---|---|---|
| KeyValuePair<TKey, TValue> | item | The object to locate in the ICollection<T>.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if   | 
      
ContainsKey(TKey)
Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.
Declaration
public virtual bool ContainsKey(TKey key)
  Parameters
| Type | Name | Description | 
|---|---|---|
| TKey | key | The key to locate in the IDictionary<TKey, TValue>.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if the IDictionary<TKey, TValue> contains an element with the key; otherwise, false.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | 
  | 
      
CopyTo(KeyValuePair<TKey, TValue>[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
Declaration
public virtual void CopyTo(KeyValuePair<TKey, TValue>[] array, int index)
  Parameters
| Type | Name | Description | 
|---|---|---|
| KeyValuePair<TKey, TValue>[] | array | The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.  | 
      
| int | index | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | 
  | 
      
| ArgumentOutOfRangeException | 
  | 
      
| ArgumentException | The number of elements in the source ICollection<T> is greater than the available space from   | 
      
Get(TKey)
LruDictionary<TKey, TValue> is similar to of Java's HashMap, which has a bounded Limit; When it reaches that Limit, each time a new element is added, the least recently used (LRU) entry is removed.
Unlike the Java Lucene implementation, this one is thread safe because it is backed by the J2N.Collections.Concurrent.LurchTable<TKey, TValue>. Do note that every time an element is read from LruDictionary<TKey, TValue>, a write operation also takes place to update the element's last access time. This is because the LRU order needs to be remembered to determine which element to evict when the Limit is exceeded.
Note
This API is experimental and might change in incompatible ways in the next release.
Declaration
public virtual TValue Get(TKey key)
  Parameters
| Type | Name | Description | 
|---|---|---|
| TKey | key | 
Returns
| Type | Description | 
|---|---|
| TValue | 
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public virtual IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
  Returns
| Type | Description | 
|---|---|
| IEnumerator<KeyValuePair<TKey, TValue>> | An enumerator that can be used to iterate through the collection.  | 
      
Put(TKey, TValue)
LruDictionary<TKey, TValue> is similar to of Java's HashMap, which has a bounded Limit; When it reaches that Limit, each time a new element is added, the least recently used (LRU) entry is removed.
Unlike the Java Lucene implementation, this one is thread safe because it is backed by the J2N.Collections.Concurrent.LurchTable<TKey, TValue>. Do note that every time an element is read from LruDictionary<TKey, TValue>, a write operation also takes place to update the element's last access time. This is because the LRU order needs to be remembered to determine which element to evict when the Limit is exceeded.
Note
This API is experimental and might change in incompatible ways in the next release.
Declaration
public virtual TValue Put(TKey key, TValue value)
  Parameters
| Type | Name | Description | 
|---|---|---|
| TKey | key | |
| TValue | value | 
Returns
| Type | Description | 
|---|---|
| TValue | 
Remove(KeyValuePair<TKey, TValue>)
Removes the first occurrence of a specific object from the ICollection<T>.
Declaration
public virtual bool Remove(KeyValuePair<TKey, TValue> item)
  Parameters
| Type | Name | Description | 
|---|---|---|
| KeyValuePair<TKey, TValue> | item | The object to remove from the ICollection<T>.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if   | 
      
Exceptions
| Type | Condition | 
|---|---|
| NotSupportedException | The ICollection<T> is read-only.  | 
      
Remove(TKey)
Removes the element with the specified key from the IDictionary<TKey, TValue>.
Declaration
public virtual bool Remove(TKey key)
  Parameters
| Type | Name | Description | 
|---|---|---|
| TKey | key | The key of the element to remove.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if the element is successfully removed; otherwise, false.  This method also returns false if   | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | 
  | 
      
| NotSupportedException | The IDictionary<TKey, TValue> is read-only.  | 
      
TryGetValue(TKey, out TValue)
Gets the value associated with the specified key.
Declaration
public virtual bool TryGetValue(TKey key, out TValue value)
  Parameters
| Type | Name | Description | 
|---|---|---|
| TKey | key | The key whose value to get.  | 
      
| TValue | value | When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the   | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if the object that implements IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | 
  |