Class MultiHashSet<T>
- Namespace
- LfrlAnvil.Collections
- Assembly
- LfrlAnvil.Collections.dll
Represents a generic multi set.
public class MultiHashSet<T> : IMultiSet<T>, IReadOnlyMultiSet<T>, IReadOnlySet<Pair<T, int>>, IReadOnlyCollection<Pair<T, int>>, ISet<Pair<T, int>>, ICollection<Pair<T, int>>, IEnumerable<Pair<T, int>>, IEnumerable where T : notnull
Type Parameters
T
Element type.
- Inheritance
-
MultiHashSet<T>
- Implements
-
IMultiSet<T>
- Inherited Members
- Extension Methods
Constructors
MultiHashSet()
Creates a new empty MultiHashSet<T> instance with Default comparer.
public MultiHashSet()
MultiHashSet(IEqualityComparer<T>)
Creates a new empty MultiHashSet<T> instance.
public MultiHashSet(IEqualityComparer<T> comparer)
Parameters
comparer
IEqualityComparer<T>Element comparer.
Properties
Comparer
Element comparer.
public IEqualityComparer<T> Comparer { get; }
Property Value
Count
Gets the number of elements contained in the ICollection<T>.
public int Count { get; }
Property Value
- int
The number of elements contained in the ICollection<T>.
DistinctItems
Gets all unique elements.
public IEnumerable<T> DistinctItems { get; }
Property Value
- IEnumerable<T>
FullCount
Gets the full count of all elements, including repetitions.
public long FullCount { get; }
Property Value
Items
Gets all elements, including repetitions.
public IEnumerable<T> Items { get; }
Property Value
- IEnumerable<T>
Methods
Add(T)
Adds the provided item
to this set once.
public int Add(T item)
Parameters
item
TElement to add.
Returns
- int
Current multiplicity of the added
item
.
AddMany(T, int)
Adds the provided item
to this set with specified number of repetitions.
public int AddMany(T item, int count)
Parameters
item
TElement to add.
count
intNumber of repetitions.
Returns
- int
Current multiplicity of the added
item
.
Exceptions
- ArgumentOutOfRangeException
When
count
is less than 1.
Clear()
Removes all items from the ICollection<T>.
public void Clear()
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
Contains(Pair<T, int>)
Determines whether the ICollection<T> contains a specific value.
[Pure]
public bool Contains(Pair<T, int> item)
Parameters
item
Pair<T, int>The object to locate in the ICollection<T>.
Returns
- bool
true if
item
is found in the ICollection<T>; otherwise, false.
Contains(T)
Checks whether or not the provided item
exists in this set.
[Pure]
public bool Contains(T item)
Parameters
item
TElement to check.
Returns
- bool
true when the provided
item
exists, otherwise false.
Contains(T, int)
Checks whether or not the provided item
exists in this set with a minimum number of repetitions.
[Pure]
public bool Contains(T item, int multiplicity)
Parameters
item
TElement to check.
multiplicity
intExpected minimum number of repetitions.
Returns
- bool
true when the provided
item
exists with a minimum number of repetitions, otherwise false.
ExceptWith(IEnumerable<Pair<T, int>>)
Removes all elements in the specified collection from the current set.
public void ExceptWith(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection of items to remove from the set.
Exceptions
- ArgumentNullException
other
is null.
GetEnumerator()
Returns an enumerator that iterates through the collection.
[Pure]
public IEnumerator<Pair<T, int>> GetEnumerator()
Returns
- IEnumerator<Pair<T, int>>
An enumerator that can be used to iterate through the collection.
GetMultiplicity(T)
Returns the number of repetitions associated with the provided item
.
[Pure]
public int GetMultiplicity(T item)
Parameters
item
TElement to get the number of repetitions for.
Returns
- int
Number of
item
repetitions.
IntersectWith(IEnumerable<Pair<T, int>>)
Modifies the current set so that it contains only elements that are also in a specified collection.
public void IntersectWith(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection to compare to the current set.
Exceptions
- ArgumentNullException
other
is null.
IsProperSubsetOf(IEnumerable<Pair<T, int>>)
Determines whether the current set is a proper (strict) subset of a specified collection.
[Pure]
public bool IsProperSubsetOf(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
other
is null.
IsProperSupersetOf(IEnumerable<Pair<T, int>>)
Determines whether the current set is a proper (strict) superset of a specified collection.
[Pure]
public bool IsProperSupersetOf(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
other
is null.
IsSubsetOf(IEnumerable<Pair<T, int>>)
Determines whether a set is a subset of a specified collection.
[Pure]
public bool IsSubsetOf(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
other
is null.
IsSupersetOf(IEnumerable<Pair<T, int>>)
Determines whether the current set is a superset of a specified collection.
[Pure]
public bool IsSupersetOf(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
other
is null.
Overlaps(IEnumerable<Pair<T, int>>)
Determines whether the current set overlaps with the specified collection.
[Pure]
public bool Overlaps(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
other
is null.
Remove(T)
Removes the provided item
from this set once.
public int Remove(T item)
Parameters
item
TElement to remove.
Returns
- int
Current multiplicity of the removed
item
or -1 if it did not exist.
RemoveAll(T)
Removes all occurrences of the provided item
from this set.
public int RemoveAll(T item)
Parameters
item
TElement to remove.
Returns
- int
Removed number of repetitions or 0 if
item
did not exist.
RemoveMany(T, int)
Removes the provided item
from this set with specified number of repetitions.
public int RemoveMany(T item, int count)
Parameters
item
TElement to remove.
count
intNumber of repetitions.
Returns
- int
Current multiplicity of the removed
item
or -1 if it did not exist.
Exceptions
- ArgumentOutOfRangeException
When
count
is less than 1.
SetEquals(IEnumerable<Pair<T, int>>)
Determines whether the current set and the specified collection contain the same elements.
[Pure]
public bool SetEquals(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
other
is null.
SetMultiplicity(T, int)
Sets the number of repetitions for the provided item
in this set.
public int SetMultiplicity(T item, int value)
Parameters
item
TElement to update.
value
intNumber of repetitions.
Returns
- int
Previous multiplicity of the updated
item
.
Remarks
Setting multiplicity to 0 is equivalent to RemoveAll(T) invocation.
Exceptions
- ArgumentOutOfRangeException
When
value
is less than 0.
SymmetricExceptWith(IEnumerable<Pair<T, int>>)
Modifies the current set so that it contains only elements that are present either in the current set or in the specified collection, but not both.
public void SymmetricExceptWith(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection to compare to the current set.
Exceptions
- ArgumentNullException
other
is null.
UnionWith(IEnumerable<Pair<T, int>>)
Modifies the current set so that it contains all elements that are present in the current set, in the specified collection, or in both.
public void UnionWith(IEnumerable<Pair<T, int>> other)
Parameters
other
IEnumerable<Pair<T, int>>The collection to compare to the current set.
Exceptions
- ArgumentNullException
other
is null.