public struct PooledDictionary<TKey, TValue> where TKey : notnullA scratch dictionary rented from a pool and cleared back into it on disposal, for the grouping and de-duplication passes a frame does and then throws away.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
What is pooled is the Dictionary`2 instance, buckets and all — not a hand-written map over rented arrays. A recycled dictionary that has already grown to the size the workload needs allocates nothing on reuse, and the alternative means owning a second hash table implementation forever to save one object header. Vixen.Core.Collections has purpose-built maps for the cases where the BCL's layout is genuinely the problem; this is not one of them.
Like PooledList`1 this is a mutable struct: copying it produces a second handle to the same dictionary, and disposing either returns it.
Fields and properties (4)
public readonly int CountHow many entries the dictionary holds.
public readonly Dictionary<TKey, TValue>.KeyCollection KeysThe keys, in the dictionary's own order.
public readonly Dictionary<TKey, TValue>.ValueCollection ValuesThe values, in the dictionary's own order.
public TValue this[TKey key]Gets or sets the value stored under .
Methods (11)
public PooledDictionary()Rents a dictionary from the pool.
public PooledDictionary(int capacity)Rents a dictionary and grows it to hold entries.
public void Add(TKey key, TValue value)Adds an entry.
public bool TryAdd(TKey key, TValue value)Adds an entry unless the key is already present.
public readonly bool TryGetValue(TKey key, out TValue value)Looks up .
public readonly bool ContainsKey(TKey key)Whether is present.
public readonly bool Remove(TKey key)Removes the entry under .
public readonly void Clear()Empties the dictionary, keeping the rental.
public Dictionary<TKey, TValue> AsDictionary()The underlying dictionary, for handing to code that takes an IDictionary`2. The reference must not outlive the rental: after Dispose it belongs to the pool and someone else will be writing to it.
public void Dispose()Clears the dictionary and returns it to the pool.
public readonly Dictionary<TKey, TValue>.Enumerator GetEnumerator()Enumerates the entries.
Used by (1)
- PoolingTestsVixen.Core.Tests