Table of Contents

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

T1

The type of the first component of the pairs.

T2

The 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

other InterlinkedDictionary<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

int

this[T1]

Gets or sets the paired value of a value of type T2.

public T2 this[T1 t1Key] { get; set; }

Parameters

t1Key T1

The value of type T1 whose paired value to get or set.

Property Value

T2

The paired value of type T2, if the value of type T1 exists.

Exceptions

ArgumentNullException

Thrown if the given value of type T1 is null.

KeyNotFoundException

Thrown if the given value of type T1 does 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

t2Key T2

The value of type T2 whose paired value to get or set.

Property Value

T1

The paired value of type T1, if the value of type T2 exists.

Exceptions

ArgumentNullException

Thrown if the given value of type T2 is null.

KeyNotFoundException

Thrown if the given value of type T2 does 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

t1Value T1

The value of type T1 to add to the dictionary.

t2Value T2

The value of type T2 to 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

value T1

The value of type T1 that 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

value T2

The value of type T2 that 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

t1Value T1

The value of type T1 that will be removed.

Returns

bool

true if the value was found and successfully removed from the dictionary, otherwise false.

Remove(T2)

Removes a from the dictionary, if it exists, otherwise nothing happens.

public bool Remove(T2 t2Value)

Parameters

t2Value T2

The value of type T2 that will be removed.

Returns

bool

true if the value was found and successfully removed from the dictionary, otherwise false.

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

t1Key T1

The value of type T1 whose paired value to get.

t2Value T2

The paired value of type T2, if t1Key exists in the dictionary, otherwise default.

Returns

bool

true if the value was present in the dictionary, otherwise false.

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

t2Key T2

The value of type T2 whose paired value to get.

t1Value T1

The paired value of type T1, if t2Key exists in the dictionary, otherwise default.

Returns

bool

true if the value was present in the dictionary, otherwise false.

ValueOrDefault(T1)

Attempts to get the paired value of a value of type T1.

public T2? ValueOrDefault(T1 key)

Parameters

key T1

The value of type T1 whose paired value to get.

Returns

T2

The paired value of type T2, if the value of type T1 exists, otherwise default.

ValueOrDefault(T2)

Attempts to get the paired value of a value of type T2.

public T1? ValueOrDefault(T2 key)

Parameters

key T2

The value of type T2 whose paired value to get.

Returns

T1

The paired value of type T1, if the value of type T2 exists, otherwise default.