CSharpUtilities::Set< T > Class Template Reference


Detailed Description

template<T>
class CSharpUtilities::Set< T >

Collection of distinct objects.

Items in a Set are unique within the Set according to the EqualityComparer used.

Set is implemented in terms of a Dictionary<T, Object>, so its performance matches that of Dictionary<T, Object>.

Template Parameters:
T Type of the Set's items.

List of all members.

Public Member Functions

  Set ()
  Construct an empty Set using the default equality comparer and default capacity.
  Set (int capacity)
  Construct an empty Set with a given minimum capacity, and using the default equality comparer.
  Set (ICollection< T > items)
  Construct a Set from a collection of items, using the default equality comparer.
  Set (IEqualityComparer< T > comparer)
  Construct an empty Set with a specific equality comparer, using the default capacity.
  Set (int capacity, IEqualityComparer< T > comparer)
  Construct an empty Set with a given capacity and a specific equality comparer.
  Set (ICollection< T > items, IEqualityComparer< T > comparer)
  Construct a Set from a collection of items, using a specific comparer.
  Set (Set< T > other)
  Construct a new Set with the same items and comparer as an existing Set.
void  Add (T item)
  Adds an item to the Set.
void  AddRange (IEnumerable< T > items)
  Adds all items in a given collection to this set.
void  Clear ()
  Removes all items from this Set.
bool  Contains (T item)
  Determines if this Set contains the given item.
void  CopyTo (T[] array, int baseIndex)
  Copies all of the items in this Set to the given array, starting at the specified base index in the array.
bool  Remove (T item)
  Removes an item from this Set.
IEnumerator< T >  GetEnumerator ()
  Get an Enumerator for iterating over this Set's items.
void  Union (IEnumerable< T > items)
  Replaces the current Set with the union of this Set and the given collection.
void  Intersection (IEnumerable< T > items)
  Replaces the current Set with the intersection of this Set and the given collection.
void  RemoveRange (IEnumerable< T > items)
  Removes all items in the given collection from this Set.

Properties

IEqualityComparer< T >  Comparer [get]
  Used to determine the equality of items in this Set.
int  Count [get]
  The current number of items in this Set.

Member Function Documentation

template<T >
CSharpUtilities::Set< T >::Set ( ) [inline]

Construct an empty Set using the default equality comparer and default capacity.

The default equality comparer is EqualityComparer<T>.Default.

Using a constructor to specify a capacity may improve efficiency by avoiding resizing while adding any initial objects.

template<T >
CSharpUtilities::Set< T >::Set ( int  capacity ) [inline]

Construct an empty Set with a given minimum capacity, and using the default equality comparer.

The default equality comparer is EqualityComparer<T>.Default.

Using a constructor to specify a capacity may improve efficiency by avoiding resizing while adding any initial objects.

Parameters:
capacity The number of elements that can be added before resizing is necessary.
template<T >
CSharpUtilities::Set< T >::Set ( ICollection< T >  items ) [inline]

Construct a Set from a collection of items, using the default equality comparer.

The default equality comparer is EqualityComparer<T>.Default.

Parameters:
items Initial collection of items to add to this Set. Since the Set is guaranteed to contain unique items, any duplicate items in the collection will be ignored.
template<T >
CSharpUtilities::Set< T >::Set ( IEqualityComparer< T >  comparer ) [inline]

Construct an empty Set with a specific equality comparer, using the default capacity.

Parameters:
comparer Used when comparing items. Every item in the Set is unique according to this comparer.
template<T >
CSharpUtilities::Set< T >::Set ( int  capacity,
IEqualityComparer< T >  comparer 
) [inline]

Construct an empty Set with a given capacity and a specific equality comparer.

Parameters:
capacity The number of elements that can be added before resizing is necessary.
comparer Used when comparing items. Every item in the Set is unique according to this comparer.
template<T >
CSharpUtilities::Set< T >::Set ( ICollection< T >  items,
IEqualityComparer< T >  comparer 
) [inline]

Construct a Set from a collection of items, using a specific comparer.

Parameters:
items Initial collection of items to add to this Set. Since the Set is guaranteed to contain unique items, any duplicate items in the collection will be ignored.
comparer Used when comparing items. Every item in the Set is unique according to this comparer.
template<T >
CSharpUtilities::Set< T >::Set ( Set< T >  other ) [inline]

Construct a new Set with the same items and comparer as an existing Set.

Parameters:
other Set to copy.
template<T >
void CSharpUtilities::Set< T >::Add ( item ) [inline]

Adds an item to the Set.

If this.Contains(item), item is ignored.

Parameters:
item Item to add.
template<T >
void CSharpUtilities::Set< T >::AddRange ( IEnumerable< T >  items ) [inline]

Adds all items in a given collection to this set.

Any duplicate items in items and any items already in this Set will be ignored.

Parameters:
items Collection of items to add.
template<T >
void CSharpUtilities::Set< T >::Clear ( ) [inline]

Removes all items from this Set.

template<T >
bool CSharpUtilities::Set< T >::Contains ( item ) [inline]

Determines if this Set contains the given item.

Parameters:
item Item to locate in this Set.
Returns:
true if the item is in this Set. false otherwise.
template<T >
void CSharpUtilities::Set< T >::CopyTo ( T[]  array,
int  baseIndex 
) [inline]

Copies all of the items in this Set to the given array, starting at the specified base index in the array.

Parameters:
array Destination one-dimensional array into which this Set's items will be copied.
baseIndex Starting index in the destination array at which to begin copying elements.
Exceptions:
ArgumentException Throws if array.Length - baseIndex < this.Count.
ArgumentOutOfRangeException Throws if baseIndex < 0
ArgumentNullException Throws if array is null.
template<T >
bool CSharpUtilities::Set< T >::Remove ( item ) [inline]

Removes an item from this Set.

If the item is not a member of this Set, this Set remains unchanged.

Parameters:
item Item to remove from this Set.
Returns:
true if an item was removed. false if the item was not present.
template<T >
IEnumerator<T> CSharpUtilities::Set< T >::GetEnumerator ( ) [inline]

Get an Enumerator for iterating over this Set's items.

Returns:
An Enumerator for iterating over this Set's items.
template<T >
void CSharpUtilities::Set< T >::Union ( IEnumerable< T >  items ) [inline]

Replaces the current Set with the union of this Set and the given collection.

After applying Union, this Set will have all the original items from this Set, and all distinct items from the passed in collection.

Parameters:
items Collection of items to unite with this Set.
template<T >
void CSharpUtilities::Set< T >::Intersection ( IEnumerable< T >  items ) [inline]

Replaces the current Set with the intersection of this Set and the given collection.

After applying Intersection, this Set will contain all distinct items that exist in both this original Set and in the given collection.

Parameters:
items Collection of items to intersect with this Set.
template<T >
void CSharpUtilities::Set< T >::RemoveRange ( IEnumerable< T >  items ) [inline]

Removes all items in the given collection from this Set.

Any items in the given collection that are not presented in this Set are ignored.

Parameters:
items Collection of items to remove from this Set.

Property Documentation

template<T >
IEqualityComparer<T> CSharpUtilities::Set< T >::Comparer [get]

Used to determine the equality of items in this Set.

template<T >
int CSharpUtilities::Set< T >::Count [get]

The current number of items in this Set.