These will be useful in stream operators, row indexing, etc. * AggregateList * DeltaList * DictionarySetWrapper * ImmutableOrderedDictionary * IMutableListFacade - inherits IReadOnlyList<T> and IList<T> - throws NotSupportedException in default impls for mutation ops * IMutableCollectionFacade - inherits IReadOnlyCollection<T> and ICollection<T> - throws NotSupportedException in default impls for mutation ops * MergedSortedList * OrderedDictionary * ReverseArrayList * SliceList * StepList
29 lines
1.0 KiB
C#
29 lines
1.0 KiB
C#
#nullable enable
|
|
namespace Spark.Core.Collections;
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
/// <summary>
|
|
/// Represents a unit of change that can be applied to a list.
|
|
/// </summary>
|
|
public readonly struct BlockTransaction<T> {
|
|
public readonly int Index;
|
|
public readonly int NumRemoved;
|
|
public readonly ImmutableList<T> InsertedValues;
|
|
public readonly int InitialOffset;
|
|
|
|
public BlockTransaction(int index, int initialOffset, int numRemoved = 0, ImmutableList<T>? insertedValues = null) {
|
|
Index = index;
|
|
NumRemoved = numRemoved;
|
|
InsertedValues = insertedValues ?? ImmutableList<T>.Empty;
|
|
InitialOffset = initialOffset;
|
|
}
|
|
|
|
public int Offset => InsertedValues.Count - NumRemoved;
|
|
public int CummulativeOffset => InitialOffset + Offset;
|
|
public int DestIndex => Index + InitialOffset;
|
|
|
|
public override string ToString() =>
|
|
$"{{ \"src\": {Index}, \"dst\": {DestIndex}, \"ins\": {InsertedValues.Count}, \"rem\": {NumRemoved} \"initOff\": {InitialOffset}, \"cumOff\": {CummulativeOffset} }}";
|
|
}
|