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

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

ValenceSet

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

ValenceSet

#
Creates a valence set with a custom comparer.
public ValenceSet(
comparer
Custom comparer.
)

Properties

AllValues

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

Count

#
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.
public int Count { get; }

DistinctCount

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

DistinctValues

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

HighestValence

#
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.
public int HighestValence { get; }

LowestValence

#
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.
public int LowestValence { get; }

Methods

Add

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

Add

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

Clear

#
Clear the entire set.
public void Clear()

Contains

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

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.
public IEnumerator<(T value, int valence)> GetEnumerator()

Remove

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

Remove

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

RemoveAll

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

IEnumerable.GetEnumerator

#
IEnumerator IEnumerable.GetEnumerator()

Valence

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

Operators

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