15.01.2013 Views

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The commonality of these types is captured by the interface<br />

ISet.<br />

For historical reasons, HashSet lives in System.Core.dll<br />

(whereas SortedSet and ISet live in System.dll).<br />

HashSet is implemented with a hashtable that stores just keys; SortedSet is<br />

implemented with a red/black tree.<br />

Here’s the definition for HashSet:<br />

public class HashSet : ICollection, IEnumerable, IEnumerable<br />

{<br />

// Constructors<br />

public HashSet();<br />

public HashSet (IEnumerable collection);<br />

public HashSet (IEqualityComparer comparer);<br />

public HashSet (IEnumerable collection, IEqualityComparer comparer);<br />

// Testing for membership<br />

public bool Contains (T item);<br />

// Adding / removing<br />

public bool Add (T item);<br />

public bool Remove (T item);<br />

public int RemoveWhere (Predicate match);<br />

public void Clear();<br />

// Set operations - destructive<br />

public void UnionWith (IEnumerable other); // Adds<br />

public void IntersectWith (IEnumerable other); // Removes<br />

public void ExceptWith (IEnumerable other); // Removes<br />

public void SymmetricExceptWith (IEnumerable other); // Removes<br />

// Set operations - bool<br />

public bool IsSubsetOf (IEnumerable other);<br />

public bool IsProperSubsetOf (IEnumerable other);<br />

public bool IsSupersetOf (IEnumerable other);<br />

public bool IsProperSupersetOf (IEnumerable other);<br />

public bool Overlaps (IEnumerable other);<br />

public bool SetEquals (IEnumerable other);<br />

// Other<br />

public int Count { get; }<br />

public IEqualityComparer Comparer { get; }<br />

public void CopyTo (T[] array);<br />

public void CopyTo (T[] array, int arrayIndex);<br />

public void CopyTo (T[] array, int arrayIndex, int count);<br />

public void TrimExcess();<br />

public static IEqualityComparer CreateSetComparer();<br />

}<br />

SortedSet offers the same set of members, plus the following:<br />

290 | Chapter 7: Collections

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!