Class WeakIdentityMap<TKey, TValue>
Implements a combination of java.util.WeakHashMap
and
java.util.IdentityHashMap
.
Useful for caches that need to key off of a ==
comparison
instead of a .Equals(object)
.
This class is not a general-purpose
This implementation was forked from Apache CXF
but modified to not implement the null
keys, but those are never weak!
The map supports two modes of operation:
reapOnRead = true
: This behaves identical to ajava.util.WeakHashMap
where it also cleans up the reference queue on every read operation (Get(Object), ContainsKey(Object), Count, GetValueEnumerator()), freeing map entries of already GCed keys.reapOnRead = false
: This mode does not call Reap() on every read operation. In this case, the reference queue is only cleaned up on write operations (like Put(TKey, TValue)). This is ideal for maps with few entries where the keys are unlikely be garbage collected, but there are lots of Get(Object) operations. The code can still call Reap() to manually clean up the queue without doing a write operation.
@lucene.internal
Inheritance
Assembly: DistributedLucene.Net.dll
Syntax
public sealed class WeakIdentityMap<TKey, TValue> : object where TKey : class
Type Parameters
Name | Description |
---|---|
TKey | |
TValue |
Properties
Name | Description |
---|---|
Count | Returns the number of key-value mappings in this map. This result is a snapshot, and may not reflect unprocessed entries that will be removed before next attempted access because they are no longer referenced. NOTE: This was size() in Lucene. |
IsEmpty | Returns |
Keys | Gets an |
Values | Gets an |
Methods
Name | Description |
---|---|
Clear() | Removes all of the mappings from this map. |
ContainsKey(Object) | Returns |
Get(Object) | Returns the value to which the specified key is mapped. |
GetValueEnumerator() | Returns an iterator over all values of this map.
This iterator may return values whose key is already
garbage collected while iterator is consumed,
especially if Lucene.Net.Util.WeakIdentityMap`2.reapOnRead is NOTE: This was valueIterator() in Lucene. |
NewConcurrentHashMap() | Creates a new WeakIdentityMap<TKey, TValue> based on a |
NewConcurrentHashMap(Boolean) | Creates a new WeakIdentityMap<TKey, TValue> based on a |
NewHashMap() | Creates a new WeakIdentityMap<TKey, TValue> based on a non-synchronized |
NewHashMap(Boolean) | Creates a new WeakIdentityMap<TKey, TValue> based on a non-synchronized |
Put(TKey, TValue) | Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced. |
Reap() | This method manually cleans up the reference queue to remove all garbage
collected key/value pairs from the map. Calling this method is not needed
if |
Remove(Object) | Removes the mapping for a key from this weak hash map if it is present.
Returns the value to which this map previously associated the key,
or |