public void SymmetricExceptWith(IEnumerable <T> other) { if (Count == 0) { UnionWith(other); return; } TSetBase <T> otherAsSet = other as TSetBase <T>; if (otherAsSet != null) { foreach (T item in otherAsSet) { if (!Remove(item)) { Add(item); } } } else { // HashSet to avoid duplicates HashSet <T> set = new HashSet <T>(other); foreach (T item in set) { if (!Remove(item)) { Add(item); } } } }
public void UnionWith(IEnumerable <T> other) { TSetBase <T> otherAsSet = other as TSetBase <T>; if (otherAsSet != null) { foreach (T item in otherAsSet) { if (!Contains(item)) { Add(item); } } } else { foreach (T item in other) { if (!Contains(item)) { Add(item); } } } }
public bool Overlaps(IEnumerable <T> other) { if (Count == 0) { return(false); } TSetBase <T> otherAsSet = other as TSetBase <T>; if (otherAsSet != null) { foreach (T item in otherAsSet) { if (Contains(item)) { return(true); } } } else { foreach (T item in other) { if (Contains(item)) { return(true); } } } return(false); }
public bool SetEquals(IEnumerable <T> other) { TSetBase <T> otherAsSet = other as TSetBase <T>; if (otherAsSet != null) { if (Count != otherAsSet.Count) { return(false); } foreach (T item in otherAsSet) { if (!Contains(item)) { return(false); } } return(true); } else { foreach (T item in other) { if (!Contains(item)) { return(false); } } return(true); } }
public bool IsSupersetOf(IEnumerable <T> other) { TSetBase <T> otherAsSet = other as TSetBase <T>; if (otherAsSet != null) { if (otherAsSet.Count == 0) { return(true); } if (otherAsSet.Count > Count) { return(false); } foreach (T item in otherAsSet) { if (!Contains(item)) { return(false); } } } else { foreach (T item in other) { if (!Contains(item)) { return(false); } } } return(true); }
internal static void ToNativeInternal(IntPtr nativeBuffer, int arrayIndex, IEnumerable <T> value, ref FScriptSetHelper helper, MarshalingDelegates <T> .ToNative elementToNative) { IntPtr scriptSetAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptSet))); helper.Set = scriptSetAddress; // Make sure any existing elements are properly destroyed helper.EmptyValues(); if (value == null) { return; } unsafe { FScriptSet *set = (FScriptSet *)scriptSetAddress; IList <T> list = value as IList <T>; if (list != null) { for (int i = 0; i < list.Count; ++i) { helper.AddElement(list[i], elementToNative); } return; } HashSet <T> hashSet = value as HashSet <T>; if (hashSet != null) { foreach (T item in hashSet) { helper.AddElement(item, elementToNative); } return; } TSetBase <T> setBase = value as TSetBase <T>; if (setBase != null) { foreach (T item in setBase) { helper.AddElement(item, elementToNative); } return; } foreach (T item in value) { helper.AddElement(item, elementToNative); } } }
public void IntersectWith(IEnumerable <T> other) { TSetBase <T> otherAsSet = other as TSetBase <T>; if (otherAsSet != null) { if (otherAsSet.Count == 0) { Clear(); return; } int maxIndex = SetHelper.GetMaxIndex(); for (int i = maxIndex - 1; i >= 0; --i) { if (SetHelper.IsValidIndex(i)) { T item = Get(i); if (!otherAsSet.Contains(item)) { RemoveAtInternal(i); } } } } else { // HashSet to avoid duplicates HashSet <T> set = new HashSet <T>(other); if (set.Count == 0) { Clear(); return; } int maxIndex = SetHelper.GetMaxIndex(); for (int i = maxIndex - 1; i >= 0; --i) { if (SetHelper.IsValidIndex(i)) { T item = Get(i); if (!set.Contains(item)) { RemoveAtInternal(i); } } } } }
public bool IsProperSubsetOf(IEnumerable <T> other) { TSetBase <T> otherAsSet = other as TSetBase <T>; if (otherAsSet != null) { if (Count == 0) { return(otherAsSet.Count > 0); } if (Count >= otherAsSet.Count) { return(false); } foreach (T item in this) { if (!otherAsSet.Contains(item)) { return(false); } } return(true); } else { // HashSet to avoid duplicates HashSet <T> set = new HashSet <T>(other); if (Count == 0) { return(set.Count > 0); } if (Count >= set.Count) { return(false); } foreach (T item in this) { if (!set.Contains(item)) { return(false); } } return(true); } }
public void ExceptWith(IEnumerable <T> other) { if (Count == 0) { return; } TSetBase <T> otherAsSet = other as TSetBase <T>; if (otherAsSet != null) { foreach (T element in otherAsSet) { Remove(element); } } else { foreach (T element in other) { Remove(element); } } }
public Enumerator(TSetBase <T> set) { this.set = set; index = -1; }