Class MultiDictionary<TKey, TValue>
A dictionary that allows a key to reference multiple values.
Namespace: NanoByte.Common.Collections
Assembly: NanoByte.Common.dll
Syntax
public class MultiDictionary<TKey, TValue> : Dictionary<TKey, HashSet<TValue>>
Type Parameters
Name | Description |
---|---|
TKey | The type to use as a key to identify entries in the dictionary. |
TValue | The type to use as elements to store in the dictionary. |
Remarks
This structure internally uses hash maps, so most operations run in O(1).
Constructors
MultiDictionary()
Declaration
public MultiDictionary()
Properties
Item[TKey]
Gets a collection containing the values with the specified key.
Declaration
public IEnumerable<TValue> this[TKey key] { get; }
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to get. |
Property Value
Type | Description |
---|---|
IEnumerable<TValue> | A list of elements with the specified key. Empty list if the key was not found. |
Values
A collection containing the values in the dictionary.
Declaration
public IEnumerable<TValue> Values { get; }
Property Value
Type | Description |
---|---|
IEnumerable<TValue> |
Methods
Add(TKey, TValue)
Adds an element with the provided key and value to the dictionary.
Declaration
public void Add(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to add. |
TValue | value | The value of the element to add. |
Remove(TKey, TValue)
Removes an element with the provided key and value from the dictionary.
Declaration
public bool Remove(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to remove. |
TValue | value | The value of the element to remove. |
Returns
Type | Description |
---|---|
Boolean |
|