Table of Contents

Class ConcurrentTwoLevelDictionary<TMainKey, TSubKey, TData>

Namespace
Tharga.Toolkit
Assembly
Tharga.Toolkit.Standard.dll

A thread-safe two-level dictionary that uses a main key to access a sub-dictionary keyed by a sub key.

public class ConcurrentTwoLevelDictionary<TMainKey, TSubKey, TData>

Type Parameters

TMainKey

The type of the main dictionary key.

TSubKey

The type of the sub-dictionary key.

TData

The type of the stored data values.

Inheritance
ConcurrentTwoLevelDictionary<TMainKey, TSubKey, TData>
Inherited Members
Extension Methods

Methods

AddOrUpdate(TMainKey, TSubKey, TData)

Adds or updates a value in the two-level dictionary under the specified main key and sub key.

public (TData Before, TData After) AddOrUpdate(TMainKey mainKey, TSubKey subKey, TData data)

Parameters

mainKey TMainKey

The main dictionary key.

subKey TSubKey

The sub-dictionary key.

data TData

The data value to store.

Returns

(TData Before, TData After)

A tuple containing the previous value (Before) and the new value (After).

TryGetSubDictonary(TMainKey, out ConcurrentDictionary<TSubKey, TData>)

Attempts to retrieve the sub-dictionary associated with the specified main key.

public bool TryGetSubDictonary(TMainKey mainKey, out ConcurrentDictionary<TSubKey, TData> dictionary)

Parameters

mainKey TMainKey

The main dictionary key.

dictionary ConcurrentDictionary<TSubKey, TData>

When this method returns, contains the sub-dictionary if found; otherwise, null.

Returns

bool

True if the sub-dictionary was found; otherwise, false.

TryRemove(TMainKey, out ConcurrentDictionary<TSubKey, TData>)

Attempts to remove the sub-dictionary associated with the specified main key.

public bool TryRemove(TMainKey mainKey, out ConcurrentDictionary<TSubKey, TData> dictionary)

Parameters

mainKey TMainKey

The main dictionary key.

dictionary ConcurrentDictionary<TSubKey, TData>

When this method returns, contains the removed sub-dictionary if successful; otherwise, null.

Returns

bool

True if the sub-dictionary was removed; otherwise, false.