Class Cache<K, V>

Namespace
NOpenNLP.Tools.Util
Assembly
NOpenNLP.Tools.dll

Provides fixed size, pre-allocated, least recently used replacement cache.

NOpenNLP: upstream extends java.util.LinkedHashMap and overrides its removeEldestEntry hook to bound the size. J2N's J2N.Collections.Generic.OrderedDictionary<TKey, TValue> preserves insertion order but has no such hook, so the eviction is performed explicitly on insert.

Note that upstream constructs the map in insertion-order mode (not access-order), so the eviction policy is really first-in-first-out; that behavior is preserved here.

public class Cache<K, V> : OrderedDictionary<K, V?>, IDictionary<K, V?>, IReadOnlyDictionary<K, V?>, IDictionary, IList<KeyValuePair<K, V?>>, ICollection<KeyValuePair<K, V?>>, IReadOnlyList<KeyValuePair<K, V?>>, IReadOnlyCollection<KeyValuePair<K, V?>>, IEnumerable<KeyValuePair<K, V?>>, IList, ICollection, IEnumerable, IStructuralEquatable, IFormattable

Type Parameters

K
V
Inheritance
OrderedDictionary<K, V>
Cache<K, V>
Implements
Inherited Members
OrderedDictionary<K, V>.AsReadOnly()
OrderedDictionary<K, V>.Add(K, V)
OrderedDictionary<K, V>.TryAdd(K, V)
OrderedDictionary<K, V>.Clear()
OrderedDictionary<K, V>.ContainsKey(K)
OrderedDictionary<K, V>.ContainsValue(V)
OrderedDictionary<K, V>.IndexOf(K)
OrderedDictionary<K, V>.Remove(K)
OrderedDictionary<K, V>.Remove(K, out V)
OrderedDictionary<K, V>.TrimExcess()
OrderedDictionary<K, V>.TryGetValue(K, out V)
OrderedDictionary<K, V>.GetEnumerator()
OrderedDictionary<K, V>.GetAlternateLookup<TAlternateKey>()
OrderedDictionary<K, V>.TryGetAlternateLookup<TAlternateKey>(out OrderedDictionary<K, V>.AlternateLookup<TAlternateKey>)
OrderedDictionary<K, V>.GetSpanAlternateLookup<TAlternateKeySpan>()
OrderedDictionary<K, V>.TryGetSpanAlternateLookup<TAlternateKeySpan>(out OrderedDictionary<K, V>.SpanAlternateLookup<TAlternateKeySpan>)
OrderedDictionary<K, V>.GetHashCode()
OrderedDictionary<K, V>.ToString()
OrderedDictionary<K, V>.Capacity
OrderedDictionary<K, V>.EqualityComparer
OrderedDictionary<K, V>.Count
OrderedDictionary<K, V>.Keys
OrderedDictionary<K, V>.Values
OrderedDictionary<K, V>.this[K]

Constructors

Cache(int)

Provides fixed size, pre-allocated, least recently used replacement cache.

NOpenNLP: upstream extends java.util.LinkedHashMap and overrides its removeEldestEntry hook to bound the size. J2N's J2N.Collections.Generic.OrderedDictionary<TKey, TValue> preserves insertion order but has no such hook, so the eviction is performed explicitly on insert.

Note that upstream constructs the map in insertion-order mode (not access-order), so the eviction policy is really first-in-first-out; that behavior is preserved here.

public Cache(int capacity)

Parameters

capacity int

Properties

this[K]

public V? this[K key] { get; set; }

Parameters

key K

Property Value

V

Methods

Add(K, V)

public void Add(K key, V value)

Parameters

key K
value V

ComputeIfAbsent(K, Func<K, V>)

public V? ComputeIfAbsent(K key, Func<K, V> func)

Parameters

key K
func Func<K, V>

Returns

V

Put(K, V)

NOpenNLP: an instance method that takes precedence over the Put extension method on IDictionary<TKey, TValue>, which would otherwise assign through the interface indexer and bypass the eviction above.

public V? Put(K key, V value)

Parameters

key K
value V

Returns

V