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`2.
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.
This is a Lucene.NET EXPERIMENTAL API, use at your own risk
Inheritance
System.Object
LruDictionary<TKey, TValue>
Implements
System.Collections.Generic.IDictionary<TKey, TValue>
System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
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
|
Improve this Doc
View Source
LruDictionary(Int32)
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 |
System.Int32 |
limit |
The maximum size (in number of entries) to which the map can grow
before the least recently used entries start being removed.
Setting limit to a very large value, like System.Int32.MaxValue
is allowed, but is less efficient than
using J2N.Collections.Generic.Dictionary`2 or
System.Collections.Generic.Dictionary`2 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.
|
|
Improve this Doc
View Source
LruDictionary(Int32, 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 System.Collections.Generic.IEqualityComparer<T>.
See LUCENENET-602.
Declaration
public LruDictionary(int limit, IEqualityComparer<TKey> comparer)
Parameters
Type |
Name |
Description |
System.Int32 |
limit |
The maximum size (in number of entries) to which the map can grow
before the least recently used entries start being removed.
Setting limit to a very large value, like System.Int32.MaxValue
is allowed, but is less efficient than
using J2N.Collections.Generic.Dictionary`2 or
System.Collections.Generic.Dictionary`2 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.
|
System.Collections.Generic.IEqualityComparer<TKey> |
comparer |
The System.Collections.Generic.IEqualityComparer<T> implementation to use when comparing keys,
or null to use the default System.Collections.Generic.IEqualityComparer<T> for the type of the key.
|
Properties
|
Improve this Doc
View Source
Count
Declaration
public virtual int Count { get; }
Property Value
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
IsReadOnly
Declaration
public virtual bool IsReadOnly { get; }
Property Value
Type |
Description |
System.Boolean |
|
|
Improve this Doc
View Source
Item[TKey]
Declaration
public virtual TValue this[TKey key] { get; set; }
Parameters
Type |
Name |
Description |
TKey |
key |
|
Property Value
|
Improve this Doc
View Source
Keys
Declaration
public virtual ICollection<TKey> Keys { get; }
Property Value
Type |
Description |
System.Collections.Generic.ICollection<TKey> |
|
|
Improve this Doc
View Source
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 |
System.Int32 |
|
|
Improve this Doc
View Source
Values
Declaration
public virtual ICollection<TValue> Values { get; }
Property Value
Type |
Description |
System.Collections.Generic.ICollection<TValue> |
|
Methods
|
Improve this Doc
View Source
Add(TKey, TValue)
Declaration
public virtual void Add(TKey key, TValue value)
Parameters
Type |
Name |
Description |
TKey |
key |
|
TValue |
value |
|
|
Improve this Doc
View Source
Add(KeyValuePair<TKey, TValue>)
Declaration
public virtual void Add(KeyValuePair<TKey, TValue> item)
Parameters
Type |
Name |
Description |
System.Collections.Generic.KeyValuePair<TKey, TValue> |
item |
|
|
Improve this Doc
View Source
Clear()
Declaration
public virtual void Clear()
|
Improve this Doc
View Source
Contains(KeyValuePair<TKey, TValue>)
Declaration
public virtual bool Contains(KeyValuePair<TKey, TValue> item)
Parameters
Type |
Name |
Description |
System.Collections.Generic.KeyValuePair<TKey, TValue> |
item |
|
Returns
Type |
Description |
System.Boolean |
|
|
Improve this Doc
View Source
ContainsKey(TKey)
Declaration
public virtual bool ContainsKey(TKey key)
Parameters
Type |
Name |
Description |
TKey |
key |
|
Returns
Type |
Description |
System.Boolean |
|
|
Improve this Doc
View Source
CopyTo(KeyValuePair<TKey, TValue>[], Int32)
Declaration
public virtual void CopyTo(KeyValuePair<TKey, TValue>[] array, int index)
Parameters
Type |
Name |
Description |
System.Collections.Generic.KeyValuePair<TKey, TValue>[] |
array |
|
System.Int32 |
index |
|
|
Improve this Doc
View Source
Get(TKey)
Declaration
public virtual TValue Get(TKey key)
Parameters
Type |
Name |
Description |
TKey |
key |
|
Returns
|
Improve this Doc
View Source
GetEnumerator()
Declaration
public virtual IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
Returns
Type |
Description |
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey, TValue>> |
|
|
Improve this Doc
View Source
Put(TKey, TValue)
Declaration
public virtual TValue Put(TKey key, TValue value)
Parameters
Type |
Name |
Description |
TKey |
key |
|
TValue |
value |
|
Returns
|
Improve this Doc
View Source
Remove(TKey)
Declaration
public virtual bool Remove(TKey key)
Parameters
Type |
Name |
Description |
TKey |
key |
|
Returns
Type |
Description |
System.Boolean |
|
|
Improve this Doc
View Source
Remove(KeyValuePair<TKey, TValue>)
Declaration
public virtual bool Remove(KeyValuePair<TKey, TValue> item)
Parameters
Type |
Name |
Description |
System.Collections.Generic.KeyValuePair<TKey, TValue> |
item |
|
Returns
Type |
Description |
System.Boolean |
|
|
Improve this Doc
View Source
TryGetValue(TKey, out TValue)
Declaration
public virtual bool TryGetValue(TKey key, out TValue value)
Parameters
Type |
Name |
Description |
TKey |
key |
|
TValue |
value |
|
Returns
Type |
Description |
System.Boolean |
|
Explicit Interface Implementations
|
Improve this Doc
View Source
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type |
Description |
System.Collections.IEnumerator |
|
Implements
System.Collections.Generic.IDictionary<TKey, TValue>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable