Class HashSet<T>
- Namespace
- AlgorithmsSW.Set
- Assembly
- AlgorithmsSW.dll
Represents a hash table that uses linear probing to resolve collisions.
[ExerciseReference(3, 4, 28)]
public class HashSet<T> : ISet<T>, IEnumerable<T>, IEnumerable
Type Parameters
TThe type of the keys in the hash table.
- Inheritance
-
HashSet<T>
- Implements
-
ISet<T>IEnumerable<T>
- Inherited Members
- Extension Methods
Remarks
Linear probing is an open-addressing strategy where we look for the next available slot in the array when a collision occurs.
This version always have a prime table size, so the table hashing mechanism can work as expected.
Constructors
HashSet(IComparer<T>)
Initializes a new instance of the HashSet<T> class.
public HashSet(IComparer<T> comparer)
Parameters
comparerIComparer<T>The comparer used to compare keys.
HashSet(int, IComparer<T>)
Initializes a new instance of the HashSet<T> class.
public HashSet(int initialCapacity, IComparer<T> comparer)
Parameters
initialCapacityintThe initial capacity of the hash table.
comparerIComparer<T>The comparer used to compare keys.
Properties
Comparer
Gets the comparer used to compare items.
public IComparer<T> Comparer { get; }
Property Value
- IComparer<T>
Count
Gets the number of items in the set.
public int Count { get; }
Property Value
Methods
Add(T)
Adds an item to the set.
public void Add(T key)
Parameters
keyT
Contains(T)
Checks if the set contains an item.
public bool Contains(T key)
Parameters
keyT
Returns
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator that can be used to iterate through the collection.
Remove(T)
Removes an item from the set.
public bool Remove(T key)
Parameters
keyT