HashSetPool
Provides a shared pool of HashSet<T> instances to reduce allocations.
internal static class HashSetPool<T>Examples
Section titled “Examples”The following example uses a pooled hash set to remove duplicate values.
using System.Collections.Generic;using Hertzole.SourceGen;
public static class DuplicateRemover{ public static List<string> RemoveDuplicates(IEnumerable<string> values) { // The scope returns the set to the pool when disposed. using (HashSetPool<string>.Get(out HashSet<string> set)) { set.UnionWith(values); return new List<string>(set); } }}Methods
Section titled “Methods”Retrieves a HashSet<T> from the pool.
public static HashSet<T> Get();Returns
Section titled “Returns”A HashSet<T> from the pool.
Get(out HashSet<T>)
Section titled “Get(out HashSet<T>)”Retrieves a HashSet<T> from the pool and wraps it in a disposable scope that returns it automatically.
public static PoolScope<HashSet<T>> Get(out HashSet<T> item);When this method returns, contains the HashSet<T> retrieved from the pool.
Returns
Section titled “Returns”A disposable scope that returns the HashSet<T> to the pool when disposed.
Return(HashSet<T>)
Section titled “Return(HashSet<T>)”Returns a HashSet<T> to the pool.
public static void Return(HashSet<T> item);The HashSet<T> to return to the pool.