Enhanced C#
Language of your choice: library documentation
Properties | Public Member Functions | Protected Member Functions | List of all members
Loyc.Collections.WeakValueDictionary< K, V > Class Template Reference

A dictionary in which the values are weak. When a value has been garbage- collected, the dictionary acts as if the key is not present (except the Remove() method, which saves time by not checking whether the value is dead.) More...


Source file:
Inheritance diagram for Loyc.Collections.WeakValueDictionary< K, V >:
Loyc.Collections.Impl.DictionaryBase< K, V >

Remarks

A dictionary in which the values are weak. When a value has been garbage- collected, the dictionary acts as if the key is not present (except the Remove() method, which saves time by not checking whether the value is dead.)

This is implemented on top of a standard Dictionary. In order to allow the dictionary to be read safely while it is being enumerated, cleanup operations (to remove entries whose value has been garbage-collected) do not occur automatically during read operations. You can allow cleanups by calling AutoCleanup().

Type Constraints
V :class 

Properties

override int Count [get]
 Returns the number of dictionary entries. This value may be greater than the number of elements that are still alive. More...
 
- Properties inherited from Loyc.Collections.Impl.DictionaryBase< K, V >
abstract int Count [get]
 
bool IsReadOnly [get]
 
ICollection< TKey > Keys [get]
 
ICollection< TValue > Values [get]
 
TValue this[TKey key] [get, set]
 

Public Member Functions

 WeakValueDictionary (WeakValueDictionary< K, V > other)
 
WeakValueDictionary< K, V > Clone ()
 
bool AutoCleanup ()
 Periodically removes entries with garbage-collected values from the dictionary More...
 
void Cleanup ()
 Removes entries with garbage-collected values from the dictionary. More...
 
override void Clear ()
 
override void Add (K key, V value)
 
override bool ContainsKey (K key)
 
override bool Remove (K key)
 
override bool TryGetValue (K key, out V value)
 
override IEnumerator< KeyValuePair< K, V > > GetEnumerator ()
 
- Public Member Functions inherited from Loyc.Collections.Impl.DictionaryBase< K, V >
abstract void Add (TKey key, TValue value)
 
void Add (KeyValuePair< TKey, TValue > item)
 
abstract bool ContainsKey (TKey key)
 
abstract bool Remove (TKey key)
 
bool Remove (KeyValuePair< TKey, TValue > item)
 
abstract bool TryGetValue (TKey key, out TValue value)
 
bool Contains (KeyValuePair< TKey, TValue > item)
 
void CopyTo (KeyValuePair< TKey, TValue >[] array, int arrayIndex)
 

Protected Member Functions

override void SetValue (K key, V value)
 
- Protected Member Functions inherited from Loyc.Collections.Impl.DictionaryBase< K, V >
abstract void SetValue (TKey key, TValue value)
 Implementation of the setter for this[]. More...
 

Member Function Documentation

◆ AutoCleanup()

bool Loyc.Collections.WeakValueDictionary< K, V >.AutoCleanup ( )
inline

Periodically removes entries with garbage-collected values from the dictionary

Referenced by Loyc.SymbolPool< SymbolE >.GetIfExists().

◆ Cleanup()

void Loyc.Collections.WeakValueDictionary< K, V >.Cleanup ( )
inline

Removes entries with garbage-collected values from the dictionary.

Referenced by Loyc.Collections.WeakValueDictionary< Loyc.UString, Loyc.Symbol >.AutoCleanup().

Property Documentation

◆ Count

override int Loyc.Collections.WeakValueDictionary< K, V >.Count
get

Returns the number of dictionary entries. This value may be greater than the number of elements that are still alive.

Referenced by Loyc.Collections.WeakValueDictionary< Loyc.UString, Loyc.Symbol >.AutoCleanup().