Table of Contents

Class MultiDictionary<TKey, TValue>

Namespace
NanoByte.Common.Collections
Assembly
NanoByte.Common.dll

A dictionary that allows a key to reference multiple values.

[Serializable]
public class MultiDictionary<TKey, TValue> : Dictionary<TKey, HashSet<TValue>> where TKey : notnull

Type Parameters

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.

Inheritance
object
Dictionary<TKey, HashSet<TValue>>
MultiDictionary<TKey, TValue>
Extension Methods

Remarks

This structure internally uses hash maps, so most operations run in O(1).

Properties

this[TKey]

Gets a collection containing the values with the specified key.

[CollectionAccess(CollectionAccessType.Read)]
public IEnumerable<TValue> this[TKey key] { get; }

Parameters

key TKey

The key of the element to get.

Property Value

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.

[CollectionAccess(CollectionAccessType.Read)]
public IEnumerable<TValue> Values { get; }

Property Value

IEnumerable<TValue>

Methods

Add(TKey, TValue)

Adds an element with the provided key and value to the dictionary.

[CollectionAccess(CollectionAccessType.UpdatedContent)]
public void Add(TKey key, TValue value)

Parameters

key TKey

The key of the element to add.

value TValue

The value of the element to add.

Remove(TKey, TValue)

Removes an element with the provided key and value from the dictionary.

[CollectionAccess(CollectionAccessType.ModifyExistingContent)]
public bool Remove(TKey key, TValue value)

Parameters

key TKey

The key of the element to remove.

value TValue

The value of the element to remove.

Returns

bool

true if any elements were successfully removed; otherwise, false.