Class MultiDictionary<TKey, TValue>
- Namespace
- LfrlAnvil.Collections
- Assembly
- LfrlAnvil.Collections.dll
Represents a generic collection of (key, value-range) pairs.
public class MultiDictionary<TKey, TValue> : IMultiDictionary<TKey, TValue>, IDictionary<TKey, IReadOnlyList<TValue>>, ICollection<KeyValuePair<TKey, IReadOnlyList<TValue>>>, IReadOnlyMultiDictionary<TKey, TValue>, IReadOnlyDictionary<TKey, IReadOnlyList<TValue>>, IReadOnlyCollection<KeyValuePair<TKey, IReadOnlyList<TValue>>>, IEnumerable<KeyValuePair<TKey, IReadOnlyList<TValue>>>, ILookup<TKey, TValue>, IEnumerable<IGrouping<TKey, TValue>>, IEnumerable where TKey : notnull
Type Parameters
TKeyKey type.
TValueValue type.
- Inheritance
-
MultiDictionary<TKey, TValue>
- Implements
-
IMultiDictionary<TKey, TValue>IDictionary<TKey, IReadOnlyList<TValue>>IReadOnlyMultiDictionary<TKey, TValue>IReadOnlyDictionary<TKey, IReadOnlyList<TValue>>ILookup<TKey, TValue>IEnumerable<IGrouping<TKey, TValue>>
- Inherited Members
- Extension Methods
Constructors
MultiDictionary()
Creates a new empty MultiDictionary<TKey, TValue> instance with Default key comparer.
public MultiDictionary()
MultiDictionary(IEqualityComparer<TKey>)
Creates a new empty MultiDictionary<TKey, TValue> instance.
public MultiDictionary(IEqualityComparer<TKey> comparer)
Parameters
comparerIEqualityComparer<TKey>Key equality comparer.
Properties
Comparer
Key equality comparer.
public IEqualityComparer<TKey> Comparer { get; }
Property Value
- IEqualityComparer<TKey>
Count
Gets the number of elements contained in the ICollection<T>.
public int Count { get; }
Property Value
- int
The number of elements contained in the ICollection<T>.
this[TKey]
Gets or sets the element with the specified key.
public IReadOnlyList<TValue> this[TKey key] { get; set; }
Parameters
keyTKeyThe key of the element to get or set.
Property Value
- IReadOnlyList<TValue>
The element with the specified key.
Exceptions
- ArgumentNullException
keyis null.- KeyNotFoundException
The property is retrieved and
keyis not found.- NotSupportedException
The property is set and the IDictionary<TKey, TValue> is read-only.
Keys
Gets an ICollection<T> containing the keys of the IDictionary<TKey, TValue>.
public IReadOnlyCollection<TKey> Keys { get; }
Property Value
- IReadOnlyCollection<TKey>
An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.
Values
Gets an ICollection<T> containing the values in the IDictionary<TKey, TValue>.
public IReadOnlyCollection<IReadOnlyList<TValue>> Values { get; }
Property Value
- IReadOnlyCollection<IReadOnlyList<TValue>>
An ICollection<T> containing the values in the object that implements IDictionary<TKey, TValue>.
Methods
Add(TKey, TValue)
Adds a new entry to this dictionary.
public void Add(TKey key, TValue value)
Parameters
keyTKeyEntry's key.
valueTValueEntry's value.
AddRange(TKey, IEnumerable<TValue>)
Adds a range of entries associated with the provided key to this dictionary.
public void AddRange(TKey key, IEnumerable<TValue> values)
Parameters
keyTKeyEntry's key.
valuesIEnumerable<TValue>Range of values.
Clear()
Removes all items from the ICollection<T>.
public void Clear()
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
ContainsKey(TKey)
Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.
[Pure]
public bool ContainsKey(TKey key)
Parameters
keyTKeyThe key to locate in the IDictionary<TKey, TValue>.
Returns
- bool
true if the IDictionary<TKey, TValue> contains an element with the key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.
GetCount(TKey)
Returns the number of elements associated with the provided key.
[Pure]
public int GetCount(TKey key)
Parameters
keyTKeyKey to check.
Returns
- int
Number of elements associated with the provided
key.
GetEnumerator()
Returns an enumerator that iterates through the collection.
[Pure]
public IEnumerator<KeyValuePair<TKey, IReadOnlyList<TValue>>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<TKey, IReadOnlyList<TValue>>>
An enumerator that can be used to iterate through the collection.
Remove(TKey)
Removes all elements associated with the specified key.
public IReadOnlyList<TValue> Remove(TKey key)
Parameters
keyTKeyKey to remove.
Returns
- IReadOnlyList<TValue>
All removed elements associated with the specified
key.
Remove(TKey, TValue)
Attempts to remove a specific element associated with the specified key.
public bool Remove(TKey key, TValue value)
Parameters
keyTKeyEntry's key.
valueTValueValue to remove.
Returns
- bool
true when key exists and value has been removed, otherwise false.
RemoveAll(TKey, Predicate<TValue>)
Attempts to remove all elements associated with the specified key
that pass the provided predicate.
public int RemoveAll(TKey key, Predicate<TValue> predicate)
Parameters
keyTKeyEntry's key.
predicatePredicate<TValue>Delegate that defines which elements to remove.
Returns
- int
Number of removed elements.
RemoveAt(TKey, int)
Attempts to remove an element associated with the specified key at the provided index.
public bool RemoveAt(TKey key, int index)
Parameters
keyTKeyEntry's key.
indexint0-based position of an element to remove.
Returns
- bool
true when an element has been removed, otherwise false.
Exceptions
- ArgumentOutOfRangeException
When
indexis less than 0 or greater than or equal to the number of elements associated with the specifiedkey.
RemoveRange(TKey, int, int)
Attempts to remove a range of elements associated with the specified key.
public bool RemoveRange(TKey key, int index, int count)
Parameters
keyTKeyEntry's key.
indexint0-based position of a first element to remove.
countintTotal number of elements to remove, starting from the provided
key.
Returns
- bool
true when a range of elements has been removed, otherwise false.
Exceptions
- ArgumentOutOfRangeException
When
indexorcountis less than 0.- ArgumentException
When
indexandcountdo not denote a valid range of elements.
SetRange(TKey, IEnumerable<TValue>)
Sets a range of entries associated with the provided key in this dictionary.
public void SetRange(TKey key, IEnumerable<TValue> values)
Parameters
keyTKeyEntry's key.
valuesIEnumerable<TValue>Range of values.
TryGetValue(TKey, out IReadOnlyList<TValue>)
Gets the value associated with the specified key.
public bool TryGetValue(TKey key, out IReadOnlyList<TValue> value)
Parameters
keyTKeyThe key whose value to get.
valueIReadOnlyList<TValue>When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the
valueparameter. This parameter is passed uninitialized.
Returns
- bool
true if the object that implements IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.
Exceptions
- ArgumentNullException
keyis null.