public void CopyTo(T[] array, int arrayIndex) { int maxIndex = SetHelper.GetMaxIndex(); int index = arrayIndex; for (int i = 0; i < maxIndex; ++i) { if (SetHelper.IsValidIndex(i)) { array[index++] = Get(i); } } }
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); } } } } }