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
TElement 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
comparerIEqualityComparer<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
itemTElement 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
itemTElement to add.
countintNumber of repetitions.
Returns
- int
Current multiplicity of the added
item.
Exceptions
- ArgumentOutOfRangeException
When
countis 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
itemPair<T, int>The object to locate in the ICollection<T>.
Returns
- bool
true if
itemis 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
itemTElement to check.
Returns
- bool
true when the provided
itemexists, 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
itemTElement to check.
multiplicityintExpected minimum number of repetitions.
Returns
- bool
true when the provided
itemexists 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
otherIEnumerable<Pair<T, int>>The collection of items to remove from the set.
Exceptions
- ArgumentNullException
otheris 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
itemTElement to get the number of repetitions for.
Returns
- int
Number of
itemrepetitions.
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
otherIEnumerable<Pair<T, int>>The collection to compare to the current set.
Exceptions
- ArgumentNullException
otheris 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
otherIEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris 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
otherIEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris 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
otherIEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris 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
otherIEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris 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
otherIEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris null.
Remove(T)
Removes the provided item from this set once.
public int Remove(T item)
Parameters
itemTElement to remove.
Returns
- int
Current multiplicity of the removed
itemor -1 if it did not exist.
RemoveAll(T)
Removes all occurrences of the provided item from this set.
public int RemoveAll(T item)
Parameters
itemTElement to remove.
Returns
- int
Removed number of repetitions or 0 if
itemdid 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
itemTElement to remove.
countintNumber of repetitions.
Returns
- int
Current multiplicity of the removed
itemor -1 if it did not exist.
Exceptions
- ArgumentOutOfRangeException
When
countis 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
otherIEnumerable<Pair<T, int>>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris null.
SetMultiplicity(T, int)
Sets the number of repetitions for the provided item in this set.
public int SetMultiplicity(T item, int value)
Parameters
itemTElement to update.
valueintNumber of repetitions.
Returns
- int
Previous multiplicity of the updated
item.
Remarks
Setting multiplicity to 0 is equivalent to RemoveAll(T) invocation.
Exceptions
- ArgumentOutOfRangeException
When
valueis 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
otherIEnumerable<Pair<T, int>>The collection to compare to the current set.
Exceptions
- ArgumentNullException
otheris 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
otherIEnumerable<Pair<T, int>>The collection to compare to the current set.
Exceptions
- ArgumentNullException
otheris null.