ValenceSet<T>

References
public sealed class ValenceSet<T> : IEnumerable<(T value, int valence)>
Provides a hashset like type which also stores valences for entries. This collection is thread-safe for adding and removing, but not for enumerating.
T

Constructors

ValenceSet

#
public ValenceSet()
Creates a valence set with the default comparer.

ValenceSet

#
public ValenceSet(Func<T, int> hashing, Func<T, T, bool> comparing)
Creates a valence set with custom comparisons.
hashing (Func<T, int>)Optional hashing algorithm. If omitted, the GetHashCode() method on T is invoked.
comparing (Func<T, T, bool>)Equality test.

ValenceSet

#
public ValenceSet(IEqualityComparer<T> comparer)
Creates a valence set with a custom comparer.
comparer (IEqualityComparer<T>)Custom comparer.

Properties

AllValues

#
public IEnumerable<T> AllValues { get; }
Iterate over all values. This iteration re-duplicates based on valence.

Count

#
public int Count { get; }
Gets the number of values in this set, including all duplicate ones. This property is not thread safe and should not be used while Add or Remove methods are liable to be invoked from different threads.

DistinctCount

#
public int DistinctCount { get; }
Gets the number of distinct values in this set.

DistinctValues

#
public IEnumerable<T> DistinctValues { get; }
Iterate over all distinct values.

HighestValence

#
public int HighestValence { get; }
Gets the highest valence in this set. This property is not thread safe and should not be used while Add or Remove methods are liable to be invoked from different threads.

LowestValence

#
public int LowestValence { get; }
Gets the lowest valence in this set. This property is not thread safe and should not be used while Add or Remove methods are liable to be invoked from different threads.

Methods

Add

#
public int Add(T value, int valence)
Add a new value with a custom valence to this set.
value (T)Value to add.
valence (int)Custom valence.
New valence of value.

Add

#
public int Add(T value)
Add a new value to this set.
value (T)Value to add.
New valence of value.

Clear

#
public void Clear()
Clear the entire set.

Contains

#
public bool Contains(T value)
Gets whether the given value is contained within this set.
value (T)Value to test.
True if value occurs at least once.

GetEnumerator

#
public IEnumerator<(T value, int valence)> GetEnumerator()
Enumerate over all values and their associated valences in this set. This method is not thread safe and should not be used while Add or Remove methods are liable to be invoked from different threads.

Remove

#
public int Remove(T value, int valence)
Remove a value with a custom valence from this set.
value (T)Value to remove.
valence (int)Valence to remove. If this set contains fewer than valence values, they will all be removed.
New valence of value.

Remove

#
public int Remove(T value)
Remove a single value from this set.
value (T)Value to remove.
New valence of value.

RemoveAll

#
public bool RemoveAll(T value)
Remove all values from this set.
value (T)Value to remove.
True if any values were removed.
Explicit

IEnumerable.GetEnumerator

#
IEnumerator IEnumerable.GetEnumerator()

Valence

#
public int Valence(T value)
Gets the valence of the given value. If the value is not part of this set, zero is returned.
value (T)Value to test.
Valence of value.

Operators

OperationResultDescription
ValenceSet<T>+ValenceSet<T>ValenceSet<T>Merge two sets.