/// <summary> /// Determines whether a Set object is a subset of the specified collection /// </summary> /// <param name="other">The collection to compare to the current Set object</param> /// <returns>True if the Set object is a subset of other or false, if isn't.</returns> public bool SubsetWith(CustomSet <T> other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } for (int i = 0; i < Count; i++) { if (!other._container.Contains(_container[i])) { return(false); } } return(true); }
/// <summary> /// Modifies the current Set to contain all elements that are present in itself, the specified collection, or both /// </summary> /// <param name="other">The collection to compare to the current Set</param> public void UnionWith(CustomSet <T> other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } var resultSet = _container; for (int i = 0; i < other.Count; i++) { if (!resultSet.Contains(other._container[i])) { resultSet = new T[Count + 1]; Array.Copy(_container, 0, resultSet, 0, Count); resultSet[Count] = other._container[i]; _container = resultSet; } } }
/// <summary> /// Removes all elements in the specified collection from the current Set object /// </summary> /// <param name="other">The collection of items to remove from the Set object</param> public void DifferenceWith(CustomSet <T> other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } int countOfResultSet = 0; var resultSet = new T[countOfResultSet]; for (int i = 0; i < Count; i++) { if (!other._container.Contains(_container[i])) { var newResultSet = new T[countOfResultSet + 1]; Array.Copy(resultSet, 0, newResultSet, 0, countOfResultSet); newResultSet[countOfResultSet] = _container[i]; resultSet = newResultSet; countOfResultSet++; } } _container = resultSet; }