#if STANDARD using ICD.Common.Properties; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ICD.NetStandard.Common.Utils.Extensions { public static class HashSetExtensions { [PublicAPI] public static HashSet Subtract(this HashSet extends, IEnumerable set) { HashSet subtractSet = new HashSet(extends); if (set == null) return subtractSet; foreach (T item in set) subtractSet.Remove(item); return subtractSet; } [PublicAPI] public static bool IsSubsetOf(this HashSet extends, HashSet set) { HashSet setToCompare = set ?? new HashSet(); return extends.All(setToCompare.Contains); } [PublicAPI] public static HashSet Intersection(this HashSet extends, HashSet set) { HashSet intersectionSet = new HashSet(); if (set == null) return intersectionSet; foreach (T item in extends.Where(set.Contains)) intersectionSet.Add(item); foreach (T item in set.Where(extends.Contains)) intersectionSet.Add(item); return intersectionSet; } /// /// Returns items that are not common between both sets. /// /// /// [PublicAPI] public static HashSet NonIntersection(this HashSet extends, HashSet set) { return new HashSet(extends.Subtract(set).Union(set.Subtract(extends))); } [PublicAPI] public static bool IsProperSubsetOf(this HashSet extends, HashSet set) { HashSet setToCompare = set ?? new HashSet(); // Is a proper subset if A is a subset of B and A != B return (extends.IsSubsetOf(setToCompare) && !setToCompare.IsSubsetOf(extends)); } [PublicAPI] public static bool IsSupersetOf(this HashSet extends, HashSet set) { HashSet setToCompare = set ?? new HashSet(); return setToCompare.IsSubsetOf(extends); } [PublicAPI] public static bool IsProperSupersetOf(this HashSet extends, HashSet set) { HashSet setToCompare = set ?? new HashSet(); // B is a proper superset of A if B is a superset of A and A != B return (extends.IsSupersetOf(setToCompare) && !setToCompare.IsSupersetOf(extends)); } } } #endif