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
TKeyThe type of the key.
- Inheritance
-
BaseFlexDictionary<TKey, int>FlexDictionary<TKey, int>ValueCounterDictionary<TKey>
- Implements
-
IDictionary<TKey, int>
- 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
otherValueCounterDictionary<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
kvpsIEnumerable<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
collectionIEnumerable<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
collectionIEnumerable<TKey>The collection to initialize the dictionary from.
initialValueintThe initial value to map each key to.
ValueCounterDictionary(int)
Initializes a new instance of the ValueCounterDictionary<TKey> class.
public ValueCounterDictionary(int capacity)
Parameters
capacityintThe 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
keyTKeyThe key whose counter to add a value to.
valueintThe 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
fromTKeyThe key whose counter to subtract the value from.
toTKeyThe key whose counter to add the value to.
adjustmentintThe 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
keyTKeyThe key whose counter to subtract a value from.
valueintThe value to subtract from the key's counter.