Class InterlinkedDictionary<T1, T2>
- Namespace
- Garyon.DataStructures
- Assembly
- Garyon.dll
Represents a collection of interlinked key-value pairs, where both the key and the value are mapped to each other. This means that the ability to get the mapping key from the mapped value is enabled.
public class InterlinkedDictionary<T1, T2> where T1 : notnull where T2 : notnull
Type Parameters
T1The type of the first component of the pairs.
T2The type of the second component of the pairs.
- Inheritance
-
InterlinkedDictionary<T1, T2>
- Inherited Members
- Extension Methods
Constructors
InterlinkedDictionary()
Initializes a new empty InterlinkedDictionary<T1, T2>.
public InterlinkedDictionary()
InterlinkedDictionary(InterlinkedDictionary<T1, T2>)
Initializes a new InterlinkedDictionary<T1, T2> out of another, copying the pairs to this new instance.
public InterlinkedDictionary(InterlinkedDictionary<T1, T2> other)
Parameters
otherInterlinkedDictionary<T1, T2>The other InterlinkedDictionary<T1, T2> from which to copy the pairs. That instance remains unaffected upon performing operations on this new one.
Properties
Count
Gets the count of pairs that are present in the dictionary.
public int Count { get; }
Property Value
this[T1]
Gets or sets the paired value of a value of type
T2.
public T2 this[T1 t1Key] { get; set; }
Parameters
t1KeyT1The value of type
T1whose paired value to get or set.
Property Value
- T2
The paired value of type
T2, if the value of typeT1exists.
Exceptions
- ArgumentNullException
Thrown if the given value of type
T1is null.- KeyNotFoundException
Thrown if the given value of type
T1does not exist in the dictionary.
this[T2]
Gets or sets the paired value of a value of type
T1.
public T1 this[T2 t2Key] { get; set; }
Parameters
t2KeyT2The value of type
T2whose paired value to get or set.
Property Value
- T1
The paired value of type
T1, if the value of typeT2exists.
Exceptions
- ArgumentNullException
Thrown if the given value of type
T2is null.- KeyNotFoundException
Thrown if the given value of type
T2does not exist in the dictionary.
ValuePairs
Gets all the currently stored pairs of values.
[ExcludeFromCodeCoverage]
public IEnumerable<(T1, T2)> ValuePairs { get; }
Property Value
- IEnumerable<(T1, T2)>
Values1
Gets all the currently stored values of type T1.
public IEnumerable<T1> Values1 { get; }
Property Value
- IEnumerable<T1>
Values2
Gets all the currently stored values of type T2.
public IEnumerable<T2> Values2 { get; }
Property Value
- IEnumerable<T2>
Methods
Add(T1, T2)
Adds a pair of values to the dictionary. If any of the values already exists,
public void Add(T1 t1Value, T2 t2Value)
Parameters
t1ValueT1The value of type
T1to add to the dictionary.t2ValueT2The value of type
T2to add to the dictionary.
Exceptions
- ArgumentException
Thrown if one of the values already exists in the dictionary.
- ArgumentNullException
Thrown if any of the values is null.
Clear()
Clears the dictionary, removing all pairs of values that are currently stored.
public void Clear()
Contains(T1)
Determines whether a value is contained.
public bool Contains(T1 value)
Parameters
valueT1The value of type
T1that may be contained.
Returns
- bool
A value determining whether the value is contained.
Contains(T2)
Determines whether a value is contained.
public bool Contains(T2 value)
Parameters
valueT2The value of type
T2that may be contained.
Returns
- bool
A value determining whether the value is contained.
Remove(T1)
Removes a from the dictionary, if it exists, otherwise nothing happens.
public bool Remove(T1 t1Value)
Parameters
t1ValueT1The value of type
T1that will be removed.
Returns
Remove(T2)
Removes a from the dictionary, if it exists, otherwise nothing happens.
public bool Remove(T2 t2Value)
Parameters
t2ValueT2The value of type
T2that will be removed.
Returns
TryGetValue(T1, out T2?)
Attempts to get the paired value of a value of type
T1.
public bool TryGetValue(T1 t1Key, out T2? t2Value)
Parameters
t1KeyT1The value of type
T1whose paired value to get.t2ValueT2The paired value of type
T2, ift1Keyexists in the dictionary, otherwise default.
Returns
TryGetValue(T2, out T1?)
Attempts to get the paired value of a value of type
T2.
public bool TryGetValue(T2 t2Key, out T1? t1Value)
Parameters
t2KeyT2The value of type
T2whose paired value to get.t1ValueT1The paired value of type
T1, ift2Keyexists in the dictionary, otherwise default.
Returns
ValueOrDefault(T1)
Attempts to get the paired value of a value of type
T1.
public T2? ValueOrDefault(T1 key)
Parameters
keyT1The value of type
T1whose paired value to get.
Returns
- T2
The paired value of type
T2, if the value of typeT1exists, otherwise default.
ValueOrDefault(T2)
Attempts to get the paired value of a value of type
T2.
public T1? ValueOrDefault(T2 key)
Parameters
keyT2The value of type
T2whose paired value to get.
Returns
- T1
The paired value of type
T1, if the value of typeT2exists, otherwise default.