Foley.Utilities.Collections
Class HashSet

A Hash Set implementation extending the abstract Foley.Utilities.Collections.SetBase class.

For details on how inital capacitys, load factors, hash code providers, and comparers work please see System.Collections.Hashtable for details. Will not except null objects.

Field Summary
object DUMMY
System.Collections.Hashtable table

Constructor Summary
HashSet()
         Initializes a new instance of the Foley.Utilities.Collections.HashSet class that is empty.
HashSet(int initialCapacity)
         Creates an empty Foley.Utilities.Collections.HashSet with the specified initial capacity and using the default load factor, the default hash code provider and the default comparer.
HashSet(int initialCapacity, float loadFactor)
         Creates an empty Foley.Utilities.Collections.HashSet with the specified initial capacity and using the specified load factor, the default hash code provider and the default comparer.
HashSet(System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer)
         Creates an empty Foley.Utilities.Collections.HashSet with the default initial capacity and using the default load factor, the specified hash code provider and the specified comparer.
HashSet(int initialCapacity, System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer)
         Creates an empty Foley.Utilities.Collections.HashSet with the specified initial capacity and using the default load factor, the specified hash code provider and the specified comparer.
HashSet(int initialCapacity, float loadFactor, System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer)
         Creates an empty Foley.Utilities.Collections.HashSet with the specified initial capacity and using the specified load factor, the specified hash code provider and the specified comparer.
HashSet(System.Collections.ICollection collection)
         Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection.
HashSet(System.Collections.ICollection collection, int initialCapacity)
         Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the specified initial capacity and using the specified load factor, the default hash code provider and the default comparer.
HashSet(System.Collections.ICollection collection, int initialCapacity, float loadFactor)
         Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the specified initial capacity and using the specified load factor, the default hash code provider and the default comparer.
HashSet(System.Collections.ICollection collection, System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer)
         Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the default initial capacity and using the default load factor, the specified hash code provider and the specified comparer.
HashSet(System.Collections.ICollection collection, int initialCapacity, System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer)
         Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the specified initial capacity and using the default load factor, the specified hash code provider and the specified comparer.
HashSet(System.Collections.ICollection collection, int initialCapacity, float loadFactor, System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer)
         Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the specified initial capacity and using the specified load factor, the specified hash code provider and the specified comparer.

Property Summary
int Count
         Gets the number of elements contained in the Foley.Utilities.Collections.HashSet.
bool IsEmpty
         Gets a value idicating whether the Foley.Utilities.Collections.HashSet is empty or not.
object SyncRoot
         Gets an System.Object that can be used to synchronize access to the Foley.Utilities.Collections.HashSet.

Properties inherited from class Foley.Utilities.Collections.Collection2Base
IsFixedSize, IsReadOnly, IsSynchronized

Method Summary
bool Add(System.Collections.ICollection collection)
         Adds the elements of an System.Collections.ICollection into the Foley.Utilities.Collections.HashSet.
bool Add(object value)
         Adds an System.Object into the Foley.Utilities.Collections.HashSet.
void Clear()
         Removes all elements from the Foley.Utilities.Collections.HashSet.
object Clone()
         Creates a shallow copy of the Foley.Utilities.Collections.HashSet.
Foley.Utilities.Collections.HashSet Clone(bool attemptDeepCopy)
         Attempts to make a deep copy of the Foley.Utilities.Collections.HashSet.
bool Contains(System.Collections.ICollection collection)
         Determines whether all the elements in the specified collection are contained in the Foley.Utilities.Collections.HashSet.
bool Contains(object value)
         Determines whether an System.Object is in the Foley.Utilities.Collections.HashSet.
void CopyTo(System.Array array, int index)
         Copies the entire Foley.Utilities.Collections.HashSet to a compatible one-dimensional System.Array, starting at the specified index of the target array.
System.Collections.IEnumerator GetEnumerator()
         Returns an System.Collections.IEnumerator for the entire Foley.Utilities.Collections.HashSet.
bool Remove(object value)
         Removes the occurrence of the specific System.Object from the Foley.Utilities.Collections.HashSet.

Methods inherited from class Foley.Utilities.Collections.SetBase
Remove, Retain

Methods inherited from class Foley.Utilities.Collections.Collection2Base
IsContainedIn

Methods inherited from class System.Object
Equals, Finalize, GetHashCode, GetType, MemberwiseClone, ToString


Field Detail

DUMMY

private object DUMMY


table

private System.Collections.Hashtable table

Constructor Detail

HashSet

public HashSet()

Initializes a new instance of the Foley.Utilities.Collections.HashSet class that is empty.


HashSet

public HashSet(int initialCapacity)

Creates an empty Foley.Utilities.Collections.HashSet with the specified initial capacity and using the default load factor, the default hash code provider and the default comparer.

Parameters:
initialCapacity - The approximate number of elements that the Foley.Utilities.Collections.HashSet can initially contain.
Throws:
System.ArgumentOutOfRangeException - capacity is less than zero.

HashSet

public HashSet(int initialCapacity,
               float loadFactor)

Creates an empty Foley.Utilities.Collections.HashSet with the specified initial capacity and using the specified load factor, the default hash code provider and the default comparer.

Parameters:
initialCapacity - The approximate number of elements that the Foley.Utilities.Collections.HashSet can initially contain.
loadFactor - A number in the range from 0.1 through 1.0 indicating the maximum ratio of elements to buckets.
Throws:
System.ArgumentOutOfRangeException - capacity is less than zero. -or-loadFactor is less than 0.1. -or-loadFactor is greater than 1.0.

HashSet

public HashSet(System.Collections.IHashCodeProvider hcp,
               System.Collections.IComparer comparer)

Creates an empty Foley.Utilities.Collections.HashSet with the default initial capacity and using the default load factor, the specified hash code provider and the specified comparer.

Parameters:
hcp - The System.Collections.IHashCodeProvider that supplies the hash codes for all elements in the Foley.Utilities.Collections.HashSet. -or- A null reference (Nothing in Visual Basic) to use the default hash code provider, which is each element's implementation of System.Object.GetHashCode.
comparer - The System.Collections.IComparer to use to determine whether two elements are equal. -or- A null reference (Nothing in Visual Basic) to use the default comparer, which is each element's implementation of System.Object.Equals(System.Object).

HashSet

public HashSet(int initialCapacity,
               System.Collections.IHashCodeProvider hcp,
               System.Collections.IComparer comparer)

Creates an empty Foley.Utilities.Collections.HashSet with the specified initial capacity and using the default load factor, the specified hash code provider and the specified comparer.

Parameters:
initialCapacity - The approximate number of elements that the Foley.Utilities.Collections.HashSet can initially contain.
hcp - The System.Collections.IHashCodeProvider that supplies the hash codes for all elements in the Foley.Utilities.Collections.HashSet. -or- A null reference (Nothing in Visual Basic) to use the default hash code provider, which is each element's implementation of System.Object.GetHashCode.
comparer - The System.Collections.IComparer to use to determine whether two elements are equal. -or- A null reference (Nothing in Visual Basic) to use the default comparer, which is each element's implementation of System.Object.Equals(System.Object).
Throws:
System.ArgumentOutOfRangeException - capacity is less than zero.

HashSet

public HashSet(int initialCapacity,
               float loadFactor,
               System.Collections.IHashCodeProvider hcp,
               System.Collections.IComparer comparer)

Creates an empty Foley.Utilities.Collections.HashSet with the specified initial capacity and using the specified load factor, the specified hash code provider and the specified comparer.

Parameters:
initialCapacity - The approximate number of elements that the Foley.Utilities.Collections.HashSet can initially contain.
loadFactor - A number in the range from 0.1 through 1.0 indicating the maximum ratio of elements to buckets.
hcp - The System.Collections.IHashCodeProvider that supplies the hash codes for all elements in the Foley.Utilities.Collections.HashSet. -or- A null reference (Nothing in Visual Basic) to use the default hash code provider, which is each element's implementation of System.Object.GetHashCode.
comparer - The System.Collections.IComparer to use to determine whether two elements are equal. -or- A null reference (Nothing in Visual Basic) to use the default comparer, which is each element's implementation of System.Object.Equals(System.Object).
Throws:
System.ArgumentOutOfRangeException - capacity is less than zero. -or-loadFactor is less than 0.1. -or-loadFactor is greater than 1.0.

HashSet

public HashSet(System.Collections.ICollection collection)

Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection.

Parameters:
collection - The System.Collections.ICollection whose elements are copied to the new list.

HashSet

public HashSet(System.Collections.ICollection collection,
               int initialCapacity)

Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the specified initial capacity and using the specified load factor, the default hash code provider and the default comparer.

Parameters:
collection - The System.Collections.ICollection whose elements are copied to the new list.
initialCapacity - The approximate number of elements that the Foley.Utilities.Collections.HashSet can initially contain.
Throws:
System.ArgumentOutOfRangeException - capacity is less than zero.

HashSet

public HashSet(System.Collections.ICollection collection,
               int initialCapacity,
               float loadFactor)

Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the specified initial capacity and using the specified load factor, the default hash code provider and the default comparer.

Parameters:
collection - The System.Collections.ICollection whose elements are copied to the new list.
initialCapacity - The approximate number of elements that the Foley.Utilities.Collections.HashSet can initially contain.
loadFactor - A number in the range from 0.1 through 1.0 indicating the maximum ratio of elements to buckets.
Throws:
System.ArgumentOutOfRangeException - capacity is less than zero. -or-loadFactor is less than 0.1. -or-loadFactor is greater than 1.0.

HashSet

public HashSet(System.Collections.ICollection collection,
               System.Collections.IHashCodeProvider hcp,
               System.Collections.IComparer comparer)

Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the default initial capacity and using the default load factor, the specified hash code provider and the specified comparer.

Parameters:
collection - The System.Collections.ICollection whose elements are copied to the new list.
hcp - The System.Collections.IHashCodeProvider that supplies the hash codes for all elements in the Foley.Utilities.Collections.HashSet. -or- A null reference (Nothing in Visual Basic) to use the default hash code provider, which is each element's implementation of System.Object.GetHashCode.
comparer - The System.Collections.IComparer to use to determine whether two elements are equal. -or- A null reference (Nothing in Visual Basic) to use the default comparer, which is each element's implementation of System.Object.Equals(System.Object).

HashSet

public HashSet(System.Collections.ICollection collection,
               int initialCapacity,
               System.Collections.IHashCodeProvider hcp,
               System.Collections.IComparer comparer)

Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the specified initial capacity and using the default load factor, the specified hash code provider and the specified comparer.

Parameters:
collection - The System.Collections.ICollection whose elements are copied to the new list.
initialCapacity - The approximate number of elements that the Foley.Utilities.Collections.HashSet can initially contain.
hcp - The System.Collections.IHashCodeProvider that supplies the hash codes for all elements in the Foley.Utilities.Collections.HashSet. -or- A null reference (Nothing in Visual Basic) to use the default hash code provider, which is each element's implementation of System.Object.GetHashCode.
comparer - The System.Collections.IComparer to use to determine whether two elements are equal. -or- A null reference (Nothing in Visual Basic) to use the default comparer, which is each element's implementation of System.Object.Equals(System.Object).
Throws:
System.ArgumentOutOfRangeException - capacity is less than zero.

HashSet

public HashSet(System.Collections.ICollection collection,
               int initialCapacity,
               float loadFactor,
               System.Collections.IHashCodeProvider hcp,
               System.Collections.IComparer comparer)

Initializes a new instance of the Foley.Utilities.Collections.HashSet class that contains elements copied from the specified collection with the specified initial capacity and using the specified load factor, the specified hash code provider and the specified comparer.

Parameters:
collection - The System.Collections.ICollection whose elements are copied to the new list.
initialCapacity - The approximate number of elements that the Foley.Utilities.Collections.HashSet can initially contain.
loadFactor - A number in the range from 0.1 through 1.0 indicating the maximum ratio of elements to buckets.
hcp - The System.Collections.IHashCodeProvider that supplies the hash codes for all elements in the Foley.Utilities.Collections.HashSet. -or- A null reference (Nothing in Visual Basic) to use the default hash code provider, which is each element's implementation of System.Object.GetHashCode.
comparer - The System.Collections.IComparer to use to determine whether two elements are equal. -or- A null reference (Nothing in Visual Basic) to use the default comparer, which is each element's implementation of System.Object.Equals(System.Object).
Throws:
System.ArgumentOutOfRangeException - capacity is less than zero. -or-loadFactor is less than 0.1. -or-loadFactor is greater than 1.0.
Property Detail

Count

public int Count

Gets the number of elements contained in the Foley.Utilities.Collections.HashSet.

Value:
The number of elements actually contained in the Foley.Utilities.Collections.HashSet.

IsEmpty

public bool IsEmpty

Gets a value idicating whether the Foley.Utilities.Collections.HashSet is empty or not.

Value:
true if the Foley.Utilities.Collections.HashSet contains no elements; otherwise, false.

SyncRoot

public object SyncRoot

Gets an System.Object that can be used to synchronize access to the Foley.Utilities.Collections.HashSet.

Value:
An System.Object that can be used to synchronize access to the Foley.Utilities.Collections.HashSet.
Method Detail

Add

public bool Add(System.Collections.ICollection collection)

Adds the elements of an System.Collections.ICollection into the Foley.Utilities.Collections.HashSet.

Parameters:
collection - The System.Collections.ICollection whose elements should be added into the Foley.Utilities.Collections.HashSet.
Returns:
true if the Foley.Utilities.Collections.HashSet is modified; otherwise false.
Throws:
System.ArgumentNullException - The collection is a null reference (Nothing in Visual Basic).

Add

public bool Add(object value)

Adds an System.Object into the Foley.Utilities.Collections.HashSet.

Parameters:
value - The System.Object to be added into the Foley.Utilities.Collections.HashSet
Returns:
true if the Foley.Utilities.Collections.HashSet is modified; otherwise false.
Throws:
System.ArgumentNullException - The value is a null reference (Nothing in Visual Basic).

Clear

public void Clear()

Removes all elements from the Foley.Utilities.Collections.HashSet.


Clone

public object Clone()

Creates a shallow copy of the Foley.Utilities.Collections.HashSet.

If you need a deep copy to be attempted use the Foley.Utilities.Collections.HashSet.Clone(System.Boolean) method.

Returns:
A shallow copy of the Foley.Utilities.Collections.HashSet.

Clone

public Foley.Utilities.Collections.HashSet Clone(bool attemptDeepCopy)

Attempts to make a deep copy of the Foley.Utilities.Collections.HashSet.

Attempts to make a deep copy if attemptDeepCopy is true. It will attempt this by checking if an System.Object is an System.ICloneable, and then defer the process to its Clone method.

If a true deep copy is important, please check the API documentation for the elements that are contained in the list to verify how their Clone method is implemented.

Parameters:
attemptDeepCopy - If true will attempt to make a deep copy, if false it will just return a shallow copy
Returns:
The newly cloned Foley.Utilities.Collections.HashSet.
Throws:
System.SystemException - If and System.Object in the list is not an System.ICloneable.
System.SystemException - At the first System.Object that is not an System.ICloneable when attemptDeepCopy is true.

Contains

public bool Contains(System.Collections.ICollection collection)

Determines whether all the elements in the specified collection are contained in the Foley.Utilities.Collections.HashSet.

This implementation is close to O(1) in most cases.

Parameters:
collection - The System.Collections.ICollection whose elements are to be added to the end of the Foley.Utilities.Collections.HashSet.
Returns:
true if all the elements of the System.Collections.ICollection are found in the Foley.Utilities.Collections.HashSet; otherwise, false.
Throws:
System.ArgumentNullException - The collection is a null reference (Nothing in Visual Basic).

Contains

public bool Contains(object value)

Determines whether an System.Object is in the Foley.Utilities.Collections.HashSet.

This implementation is close to O(1) in most cases.

Parameters:
value - The System.Object to locate in the Foley.Utilities.Collections.HashSet. The System.Object to locate can be a null reference (Nothing in Visual Basic).
Returns:
true if value is found in the Foley.Utilities.Collections.HashSet; otherwise, false.
Throws:
System.ArgumentNullException - The value is a null reference (Nothing in Visual Basic).

CopyTo

public void CopyTo(System.Array array,
                   int index)

Copies the entire Foley.Utilities.Collections.HashSet to a compatible one-dimensional System.Array, starting at the specified index of the target array.

Parameters:
array - The one-dimensional System.Array that is the destination of the elements copied from the Foley.Utilities.Collections.HashSet. The System.Array must have zero-based indexing.
index - The zero-based index in array at which copying begins.
Throws:
System.ArgumentNullException - The array is a null reference (Nothing in Visual Basic).
System.ArgumentOutOfRangeException - The index is less than zero.
System.ArgumentException - The array is multidimensional. -or- The index is equal to or greater than the length of array. -or- The number of elements in the Foley.Utilities.Collections.HashSet is greater than the available space from index to the end of the destination array.

GetEnumerator

public System.Collections.IEnumerator GetEnumerator()

Returns an System.Collections.IEnumerator for the entire Foley.Utilities.Collections.HashSet.

Returns:
An System.Collections.IEnumerator for the entire Foley.Utilities.Collections.HashSet.

Remove

public bool Remove(object value)

Removes the occurrence of the specific System.Object from the Foley.Utilities.Collections.HashSet.

Parameters:
value - The System.Object to remove from the Foley.Utilities.Collections.HashSet.
Returns:
true if the HashSet is modified; otherwise false.
Throws:
System.ArgumentNullException - The value is a null reference (Nothing in Visual Basic).