public static HashSet <T> ToHashSetPooled <T>(this IEnumerable <T> source) { var hashSet = HashSetPool <T> .New(); foreach (var item in source) { hashSet.Add(item); } return(hashSet); }
public static IEnumerable <T> OrderByDependencies <T>(this IEnumerable <T> source, Func <T, IEnumerable <T> > getDependencies, bool throwOnCycle = true) { var sorted = new List <T>(); var visited = HashSetPool <T> .New(); foreach (var item in source) { OrderByDependenciesVisit(item, visited, sorted, getDependencies, throwOnCycle); } HashSetPool <T> .Free(visited); return(sorted); }
public static HashSet <GraphReference> ChildrenOfPooled(IGraphParent parent) { Ensure.That(nameof(parent)).IsNotNull(parent); lock (@lock) { if (byParent.TryGetValue(parent, out var instances)) { // Debug.Log($"Found {instances.Count} instances of {parent.ToSafeString()}\n{instances.ToLineSeparatedString()}"); return(instances.ToHashSetPooled()); } else { // Debug.Log($"Found no instances of {parent.ToSafeString()}.\n"); return(HashSetPool <GraphReference> .New()); } } }
public static HashSet <GraphReference> OfPooled(IGraph graph) { Ensure.That(nameof(graph)).IsNotNull(graph); lock (@lock) { if (byGraph.TryGetValue(graph, out var instances)) { // Debug.Log($"Found {instances.Count} instances of {graph}\n{instances.ToLineSeparatedString()}"); return(instances.ToHashSetPooled()); } else { // Debug.Log($"Found no instances of {graph}.\n"); return(HashSetPool <GraphReference> .New()); } } }
public static void Free <T>(this HashSet <T> hashSet) { HashSetPool <T> .Free(hashSet); }