Class HashTableWithLinearProbing2<TKey, TValue>
- Namespace
- AlgorithmsSW.HashTable
- Assembly
- AlgorithmsSW.dll
Represents a hash table that uses linear probing to resolve collisions.
[ExerciseReference(3, 4, 28)]
public class HashTableWithLinearProbing2<TKey, TValue> : ISymbolTable<TKey, TValue>, IReadOnlySymbolTable<TKey, TValue>
Type Parameters
TKeyThe type of keys in the hash table.
TValueThe type of values in the hash table.
- Inheritance
-
HashTableWithLinearProbing2<TKey, TValue>
- Implements
-
ISymbolTable<TKey, TValue>IReadOnlySymbolTable<TKey, TValue>
- Inherited Members
- Extension Methods
Constructors
HashTableWithLinearProbing2(IComparer<TKey>)
Initializes a new instance of the HashTableWithLinearProbing2<TKey, TValue> class.
public HashTableWithLinearProbing2(IComparer<TKey> comparer)
Parameters
comparerIComparer<TKey>The comparer used to compare keys.
HashTableWithLinearProbing2(int, IComparer<TKey>)
Initializes a new instance of the HashTableWithLinearProbing2<TKey, TValue> class.
public HashTableWithLinearProbing2(int initialCapacity, IComparer<TKey> comparer)
Parameters
initialCapacityintThe initial capacity of the hash table.
comparerIComparer<TKey>The comparer used to compare keys.
Properties
Comparer
public IComparer<TKey> Comparer { get; }
Property Value
- IComparer<TKey>
Count
Gets the number of key/value pairs contained in the symbol table.
public int Count { get; }
Property Value
Keys
Gets an IEnumerable<T> containing the keys of the symbol table.
public IEnumerable<TKey> Keys { get; }
Property Value
- IEnumerable<TKey>
Methods
Add(TKey, TValue)
Adds the specified key and value to the symbol table.
public void Add(TKey key, TValue value)
Parameters
keyTKeyThe key of the element to add.
valueTValueThe value of the element to add.
ContainsKey(TKey)
Determines whether the symbol table contains a specific key.
public bool ContainsKey(TKey key)
Parameters
keyTKeyThe key to locate in the symbol table.
Returns
- bool
trueif the symbol table contains an element with the specified key; otherwise,false.
RemoveKey(TKey)
Removes the element with the specified key from the symbol table.
public void RemoveKey(TKey key)
Parameters
keyTKeyThe key of the element to remove.
TryGetValue(TKey, out TValue)
Tries to get the value associated with the specified key from the symbol table.
public bool TryGetValue(TKey key, out TValue value)
Parameters
keyTKeyThe key of the value to get.
valueTValueWhen this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
Returns
- bool
trueif the symbol table contains an element with the specified key; otherwise,false.