MultiDictionary<TKey, TValue>

public class MultiDictionary<TKey, TValue>
Provides a palette with multiple values per key. This class is not optimized for large overlaps of values.
TKeyKey type.
TValueValue type.

Constructors

MultiDictionary

#
public MultiDictionary()
Create a new MultiDictionary.

MultiDictionary

#
public MultiDictionary(IEqualityComparer<TKey> comparer)
Create a new MultiDictionary with a specific comparer.
comparer (IEqualityComparer<TKey>)Equality comparer for keys.

MultiDictionary

#
public MultiDictionary(int capacity, IEqualityComparer<TKey> comparer)
Create a new MultiDictionary with a specific comparer.
capacity (int)Initial capacity.
comparer (IEqualityComparer<TKey>)Equality comparer for keys.

MultiDictionary

#
public MultiDictionary(int capacity)
Create a new MultiDictionary with a specific capacity.
capacity (int)Initial capacity.

Properties

ArrayPairs

#
public IEnumerable<KeyValuePair<TKey, TValue[]>> ArrayPairs { get; }
Gets an enumerator for all key/valuearray pairs.

HighestValence

#
public int HighestValence { get; }
Gets the highest valence in this MultiDictionary.

KeyCount

#
public int KeyCount { get; }
Gets the number of keys stored in this MultiDictionary.

Keys

#
public IEnumerable<TKey> Keys { get; }
Enumerate over all keys.

LowestValence

#
public int LowestValence { get; }
Gets the lowest valence in this MultiDictionary.

ValueArrays

#
public IEnumerable<TValue[]> ValueArrays { get; }
Enumerate over all value arrays.

ValueCount

#
public int ValueCount { get; }
Gets the number of values stored in this MultiDictionary.

Values

#
public IEnumerable<TValue> Values { get; }
Enumerate over all values.

Indexers

this[]

#
public IEnumerable<TValue> this[TKey key] { get; }
Gets all items associated with a specific key.
key (TKey)Key to retrieve.
Enumerable collection of items.

Methods

Add

#
public MultiDictionaryAddition Add(TKey key, TValue value)
Add a value to this MultiDictionary.
key (TKey)Key.
value (TValue)Value.

AddRange

#
public MultiDictionaryAddition AddRange(TKey key, IEnumerable<TValue> values)
Add values to this MultiDictionary.
key (TKey)Key.
values (IEnumerable<TValue>)Value.

Clear

#
public void Clear()
Clear the MultiDictionary.

ContainsKey

#
public bool ContainsKey(TKey key)
Test whether a specific key is defined.
key (TKey)Key to test.
True if key has been defined.

KeyValence

#
public int KeyValence(TKey key)
Gets the number of values associated with the given key.
key (TKey)Key to test.
Number of items associated with key.

Remove

#
public bool Remove(TKey key, TValue value)
Remove a specific value associated with a specific key.
key (TKey)Key associated with value.
value (TValue)Value to remove.

Remove

#
public bool Remove(TKey key)
Remove all values associated with the specified key.
key (TKey)Key to remove.

RemoveAll

#
public int RemoveAll(TValue value)
Remove all occurences of a specific value.
value (TValue)Value to remove.
Number of instances removed.

RemoveListsByLength

#
public int RemoveListsByLength(int minimum, int maximum)
Remove all entries that contain lists shorter than or longer than the specified limits.
minimum (int)Minimum allowed list length. Any entry with fewer than minimum items will be removed.
maximum (int)Maximum allowed list length. Any entry with more than maximum items will be removed.
Number of keys removed.

TryGetAll

#
public TValue[] TryGetAll(TKey key)
Try to get all values associated with a specific key.
key (TKey)Key.
Array of values associated with key.

TryGetFirst

#
public bool TryGetFirst(TKey key, out TValue value)
Try to get the get the first value associated with a specific key.
key (TKey)Key.
value (out TValue)First value associated with key.
True if a first value was found.

TryGetOne

#
public bool TryGetOne(TKey key, out TValue value)
Try to get a single value associated with the key. If the key has valence zero or higher than one, this method will return false.
key (TKey)Key to search for.
value (out TValue)Single value will be returned here.
True on success, false on failure.

ValencePairs

#
public IEnumerable<KeyValuePair<TKey, TValue>> ValencePairs(int minimum, int maximum)
Gets all key/value pairs that are within some valence range.
minimum (int)Inclusive lowest valence to include.
maximum (int)Inclusive highest valence to include.
Enumerable collection of pairs.