DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="2.5.0" />

 Chunk<T>

sealed class Chunk<T> : ReadOnlySequenceSegment<T>
using System; using System.Buffers; using System.Runtime.CompilerServices; namespace DotNext.Buffers { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] internal sealed class Chunk<[System.Runtime.CompilerServices.Nullable(2)] T> : ReadOnlySequenceSegment<T> { private Chunk([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] ReadOnlyMemory<T> segment) { base.RunningIndex = 0; base.Memory = segment; } private Chunk<T> Next([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] ReadOnlyMemory<T> segment) { long runningIndex = base.RunningIndex; return (Chunk<T>)(base.Next = new Chunk<T>(segment) { RunningIndex = runningIndex + base.Memory.Length }); } internal static void AddChunk([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] ReadOnlyMemory<T> segment, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] ref Chunk<T> first, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1 })] ref Chunk<T> last) { if (first == null || last == null) first = (last = new Chunk<T>(segment)); else last = last.Next(segment); } } }