Class Dictionary<K, V>
A dictionary implementation.
Inherited Members
Namespace: Advanced.Algorithms.DataStructures.Dictionaries
Assembly: Advanced.Algorithms.dll
Syntax
public class Dictionary<K, V> : IEnumerable<KeyValuePair<K, V>>, IEnumerable
Type Parameters
Name | Description |
---|---|
K | The key datatype. |
V | The value datatype. |
Constructors
Dictionary(DictionaryType, Int32)
Constructor.
Declaration
public Dictionary(DictionaryType type = DictionaryType.SeparateChaining, int initialBucketSize = 2)
Parameters
Type | Name | Description |
---|---|---|
DictionaryType | type | The dictionary implementation to use. |
Int32 | initialBucketSize | The larger the bucket size lesser the collision, but memory matters! |
Properties
Count
The number of items in this hashset.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Item[K]
Get/set value for given key. Time complexity: O(1) amortized.
Declaration
public V this[K key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
K | key |
Property Value
Type | Description |
---|---|
V |
Methods
Add(K, V)
Add a new key for given value. Time complexity: O(1) amortized.
Declaration
public void Add(K key, V value)
Parameters
Type | Name | Description |
---|---|---|
K | key | The key to add. |
V | value | The value for the given key. |
Clear()
Clear the dictionary. Time complexity: O(1).
Declaration
public void Clear()
ContainsKey(K)
Does this dictionary contains the given key. Time complexity: O(1) amortized.
Declaration
public bool ContainsKey(K key)
Parameters
Type | Name | Description |
---|---|---|
K | key |
Returns
Type | Description |
---|---|
Boolean | True if this dictionary contains the given key. |
GetEnumerator()
Declaration
public IEnumerator<KeyValuePair<K, V>> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<KeyValuePair<K, V>> |
Remove(K)
Remove the given key along with its value. Time complexity: O(1) amortized.
Declaration
public void Remove(K key)
Parameters
Type | Name | Description |
---|---|---|
K | key | The key to remove. |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |