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); } }