An immutable hash set where each class instance does not represent the full set but a modification of another set (possibly empty). This class implements the IIncrementalObject interface and can be easily used in the context of an IHierarchicalOptions<T>. The class can represent the Add(T), Remove(T) and Clear<T>() operations.
Implements
Namespace: Metalama.Framework.Options
Assembly: Metalama.Framework.dll
Syntax
public class IncrementalHashSet<T> : IIncrementalObject, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, ICompileTimeSerializable where T : notnullType Parameters
| Name | Description |
|---|---|
| T | Type of items. |
Remarks
IncrementalHashSet<T> is designed for use as a property type within hierarchical options classes. Unlike a regular hash set, each instance represents a layer of changes to a set rather than the complete set itself. When multiple layers are merged using ApplyChanges(IncrementalHashSet<T>, in ApplyChangesContext), the operations from each layer are combined to produce the effective final set.
For example, if one layer adds items {"A", "B"} and another layer removes {"B"} and adds {"C"}, the final merged set contains {"A", "C"}. The Clear<T>() operation creates a layer that clears all previous items, starting fresh.
This class is immutable. All operations (Add(T), Remove(T), etc.) return new instances rather than modifying the current instance.
Constructors
| Name | Description |
|---|---|
| IncrementalHashSet(ImmutableDictionary<T, bool>, bool) |
Properties
| Name | Description |
|---|---|
| Count | Gets the number of items in the current collection layer. |
| Empty | Gets an IncrementalHashSet<T> that represents the absence of any change in the collection. |
| IsEmpty | Gets a value indicating whether this collection layer is empty. |
Methods
| Name | Description |
|---|---|
| Add(IEnumerable<T>) | Creates a new IncrementalHashSet<T> that represents the operation of adding items to the collection, in addition to any operations represented by the current collection. |
| Add(T) | Creates a new IncrementalHashSet<T> that represents the operation of adding an item to the collection, in addition to any operations represented by the current collection. |
| Add(T[]) | Creates a new IncrementalHashSet<T> that represents the operation of adding items to the collection, in addition to any operations represented by the current collection. |
| ApplyChanges(IncrementalHashSet<T>, in ApplyChangesContext) | Merges the current collection layer with another collection layer and returns the result. |
| Create(ImmutableDictionary<T, bool>, bool) | |
| GetEnumerator() | Returns an enumerator that iterates through the items in the collection. |
| Remove(IEnumerable<T>) | Creates a new IncrementalHashSet<T> that represents the operation of removing items from the collection, in addition to any operations represented by the current object. |
| Remove(T) | Creates a new IncrementalHashSet<T> that represents the operation of removing an item from the collection, in addition to any operations represented by the current object. |
| Remove(T[]) | Creates a new IncrementalHashSet<T> that represents the operation of removing items from the collection, in addition to any operations represented by the current object. |