Table of Contents

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

TKey

Key type.

TValue

Value type.

Inheritance
MultiDictionary<TKey, TValue>
Implements
IMultiDictionary<TKey, TValue>
IDictionary<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

comparer IEqualityComparer<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

key TKey

The key of the element to get or set.

Property Value

IReadOnlyList<TValue>

The element with the specified key.

Exceptions

ArgumentNullException

key is null.

KeyNotFoundException

The property is retrieved and key is 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

key TKey

Entry's key.

value TValue

Entry'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

key TKey

Entry's key.

values IEnumerable<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

key TKey

The 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

key is null.

GetCount(TKey)

Returns the number of elements associated with the provided key.

[Pure]
public int GetCount(TKey key)

Parameters

key TKey

Key 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

key TKey

Key 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

key TKey

Entry's key.

value TValue

Value 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

key TKey

Entry's key.

predicate Predicate<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

key TKey

Entry's key.

index int

0-based position of an element to remove.

Returns

bool

true when an element has been removed, otherwise false.

Exceptions

ArgumentOutOfRangeException

When index is less than 0 or greater than or equal to the number of elements associated with the specified key.

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

key TKey

Entry's key.

index int

0-based position of a first element to remove.

count int

Total 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 index or count is less than 0.

ArgumentException

When index and count do 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

key TKey

Entry's key.

values IEnumerable<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

key TKey

The key whose value to get.

value IReadOnlyList<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 value parameter. 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

key is null.