Table of Contents

Class ValueCounterDictionary<TKey>

Namespace
Garyon.DataStructures
Assembly
Garyon.dll

Represents a value counter dictionary, that stores a counter per entry as the value of the key.

public class ValueCounterDictionary<TKey> : FlexDictionary<TKey, int>, IDictionary<TKey, int>, ICollection<KeyValuePair<TKey, int>>, IEnumerable<KeyValuePair<TKey, int>>, IEnumerable where TKey : notnull

Type Parameters

TKey

The type of the key.

Inheritance
ValueCounterDictionary<TKey>
Implements
Derived
Inherited Members
Extension Methods

Constructors

ValueCounterDictionary()

Initializes a new instance of the ValueCounterDictionary<TKey> class with the default initial capacity (16).

public ValueCounterDictionary()

ValueCounterDictionary(ValueCounterDictionary<TKey>)

Initializes a new instance of the ValueCounterDictionary<TKey> class out of another ValueCounterDictionary<TKey> instance.

public ValueCounterDictionary(ValueCounterDictionary<TKey> other)

Parameters

other ValueCounterDictionary<TKey>

The other ValueCounterDictionary<TKey> whose key-value pairs to copy.

ValueCounterDictionary(IEnumerable<KeyValuePair<TKey, int>>)

Initializes a new instance of the ValueCounterDictionary<TKey> class.

public ValueCounterDictionary(IEnumerable<KeyValuePair<TKey, int>> kvps)

Parameters

kvps IEnumerable<KeyValuePair<TKey, int>>

The collection of value counters, represented as KeyValuePair<TKey, TValue> objects, to initialize the dictionary from.

ValueCounterDictionary(IEnumerable<TKey>)

Initializes a new instance of the ValueCounterDictionary<TKey> class. Each item in the provided collection is added as a key and is mapped to the value of 1.

public ValueCounterDictionary(IEnumerable<TKey> collection)

Parameters

collection IEnumerable<TKey>

The collection to initialize the dictionary from.

ValueCounterDictionary(IEnumerable<TKey>, int)

Initializes a new instance of the ValueCounterDictionary<TKey> class. Each item in the provided collection is added as a key and is mapped to the specified value.

public ValueCounterDictionary(IEnumerable<TKey> collection, int initialValue)

Parameters

collection IEnumerable<TKey>

The collection to initialize the dictionary from.

initialValue int

The initial value to map each key to.

ValueCounterDictionary(int)

Initializes a new instance of the ValueCounterDictionary<TKey> class.

public ValueCounterDictionary(int capacity)

Parameters

capacity int

The capacity of the dictionary.

Methods

Add(TKey, int)

Adds a value to a key's counter.

public override void Add(TKey key, int value = 1)

Parameters

key TKey

The key whose counter to add a value to.

value int

The value to add to the key's counter.

AdjustCounters(TKey, TKey, int)

Subtracts a value from the counter of one key and adds that value on the counter of another key.

public void AdjustCounters(TKey from, TKey to, int adjustment = 1)

Parameters

from TKey

The key whose counter to subtract the value from.

to TKey

The key whose counter to add the value to.

adjustment int

The value to adjust the counters by.

Subtract(TKey, int)

Subtracts a value from a key's counter.

public void Subtract(TKey key, int value = 1)

Parameters

key TKey

The key whose counter to subtract a value from.

value int

The value to subtract from the key's counter.