Table of Contents

Interface ICounter<T>

Namespace
AlgorithmsSW.Counter
Assembly
AlgorithmsSW.dll

A data structure that keeps track of the number of times an item is added or removed.

public interface ICounter<T> : IEnumerable<KeyValuePair<T, int>>, IEnumerable

Type Parameters

T
Inherited Members
Extension Methods

Remarks

This is also sometimes called a bag (not to be confused with AlgorithmsSW.Bag), or multiset (although a multiset can also refer to an other data structure).

Properties

this[T]

Gets the number of times an item has been added (minus the number of times it has been removed).

int this[T item] { get; }

Parameters

item T

The item to get the count of.

Property Value

int

Keys

Gets the items that have been added (and not removed the same number of times).

IEnumerable<T> Keys { get; }

Property Value

IEnumerable<T>

Methods

Add(T)

Increments the count of an item by 1.

void Add(T item)

Parameters

item T

The item to add.

Clear()

Sets the count of all items to 0.

void Clear()

Remove(T)

Reduces the count of an item by 1.

void Remove(T item)

Parameters

item T

The item to remove.