SystemEX  Lacking
Additional generic collection types missing in .net
SystemEx.FlexSpan< T > Struct Template Reference

A lightweight view over an array supporting System, Reverse, and Ring (circular) indexing. FlexSpan does not allocate and provides ref-return access to elements. More...

Classes

struct  Enumerator
 Enumerator for FlexSpan. Supports forward, reverse, and ring traversal. More...

Public Member Functions

bool MoveNext ()
 Moves to the next element in the span.
void IEnumerator. Reset ()
 Resets the enumerator to the initial position. Ring mode resets to index 0; other modes reset to -1.
void IDisposable. Dispose ()
 No resources to dispose.
 FlexSpan (ref T[]? reference, long start, FlexSpanMode mode)
 Creates a FlexSpan over an array starting at a given index.
 FlexSpan (ref T[]? array, long start, long length, FlexSpanMode mode)
 Creates a FlexSpan over an array with a defined view length.
FlexSpan< T > Slice (int start, FlexSpanMode? mode=null)
 Creates a new FlexSpan starting at the given offset.
FlexSpan< T > Slice (int start, int length, FlexSpanMode? mode=null)
 Creates a new FlexSpan with a given offset and length.
override bool Equals (object? obj)
override int GetHashCode ()
Enumerator GetEnumerator ()
 Returns an enumerator for the span.
Collections.Generic.Vector< T > ToArray ()
 Copies the view into a new Array<T>.
void CopyTo (FlexSpan< T > destination)
 Copies this FlexSpan's view into another FlexSpan.
bool TryCopyTo (FlexSpan< T > destination)
 Attempts to copy the view into another FlexSpan.
void Fill (T value)
 Fills the view with a given value.
ref T ElementAt (long index)
 Returns a reference to the element at the given index according to the current mode. System = forward indexing Reverse = reverse indexing Ring = circular indexing (wrap-around).

Static Public Member Functions

static bool operator== (FlexSpan< T > left, FlexSpan< T > right)
 Structural equality comparison.
static bool operator!= (FlexSpan< T > left, FlexSpan< T > right)
 Structural not equality comparison.

Properties

bool HasNext [get]
 Indicates whether another element can be produced. Ring mode always returns true (infinite iteration).
ref T Current [get]
 Gets the element at the current enumerator position.
T IEnumerator< T >. Current [get]
object IEnumerator. Current [get]
bool IsEmpty [get]
 True if the span has zero length.
long Length [get]
 Total length of the underlying array.
long ViewLength [get]
 Length of the view (End - Start).
long Start [get]
 Start index of the view.
long End [get]
 End index of the view (exclusive).
ref T this[int index] [get]
 Provides ref-access to the element at the given index within the view.
static FlexSpan< T > Empty [get]
 Returns an empty FlexSpan.

Detailed Description

A lightweight view over an array supporting System, Reverse, and Ring (circular) indexing. FlexSpan does not allocate and provides ref-return access to elements.


Class Documentation

◆ SystemEx::FlexSpan-1-g::Enumerator

struct SystemEx::FlexSpan-1-g::Enumerator

Enumerator for FlexSpan. Supports forward, reverse, and ring traversal.

Member Function Documentation

◆ CopyTo()

void SystemEx.FlexSpan< T >.CopyTo ( FlexSpan< T > destination)

Copies this FlexSpan's view into another FlexSpan.

285 {
286 if ( destination.ViewLength < this.ViewLength )
287 throw new ArgumentException("Destination FlexSpan is too small.");
288
289
290 for ( long i = 0 ; i < ViewLength ; i++ )
291 destination.ElementAt(i) = this.ElementAt(i);
292 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dispose()

void IDisposable. SystemEx.FlexSpan< T >.Dispose ( )

No resources to dispose.

119{ }

◆ ElementAt()

ref T SystemEx.FlexSpan< T >.ElementAt ( long index)

Returns a reference to the element at the given index according to the current mode. System = forward indexing Reverse = reverse indexing Ring = circular indexing (wrap-around).

325 {
326
327 ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, ViewLength);
328
329
330 switch ( m_eMode ) {
331 case FlexSpanMode.System:
332 return ref m_pReference[m_lStart + index];
333
334 case FlexSpanMode.Reverse:
335 return ref m_pReference[m_lEnd - (1 + index)];
336
337
338 case FlexSpanMode.Ring: {
339 long pos = m_lStart + (index % ViewLength);
340
341 return ref m_pReference[pos];
342 }
343 default:
344 throw new InvalidOperationException();
345 }
346 }
FlexSpanMode
Defines how FlexSpan indexes its underlying array.
Definition FlexSpan.cs:26
Here is the caller graph for this function:

◆ Equals()

override bool SystemEx.FlexSpan< T >.Equals ( object? obj)
252=> throw new NotSupportedException();

◆ Fill()

void SystemEx.FlexSpan< T >.Fill ( T value)

Fills the view with a given value.

311 {
312
313 for ( long i = 0 ; i < ViewLength ; i++ )
314 ElementAt(i) = value;
315
316 }
Here is the call graph for this function:

◆ FlexSpan() [1/2]

SystemEx.FlexSpan< T >.FlexSpan ( ref T?[] array,
long start,
long length,
FlexSpanMode mode )

Creates a FlexSpan over an array with a defined view length.

200 {
201 if ( array == null ) throw new NullReferenceException();
202
203 ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual((ulong)length, (ulong)(array.Length - start));
204 ArgumentOutOfRangeException.ThrowIfGreaterThan((ulong)start, (ulong)array.Length);
205
206 m_pReference = ref array!;
207 m_llength = array.Length;
208 m_eMode = mode;
209
210 // View
211 m_lStart = start;
212 m_lEnd = start + length;
213
214 }

◆ FlexSpan() [2/2]

SystemEx.FlexSpan< T >.FlexSpan ( ref T?[] reference,
long start,
FlexSpanMode mode )

Creates a FlexSpan over an array starting at a given index.

183 {
184 if ( reference == null ) throw new NullReferenceException();
185 ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(start, reference.Length);
186
187 m_pReference = ref reference!;
188 m_llength = reference.Length;
189 m_eMode = mode;
190
191 // View
192 m_lStart = start;
193 m_lEnd = m_llength;
194 }
Here is the caller graph for this function:

◆ GetEnumerator()

Enumerator SystemEx.FlexSpan< T >.GetEnumerator ( )

Returns an enumerator for the span.

260=> new Enumerator(this);

◆ GetHashCode()

override int SystemEx.FlexSpan< T >.GetHashCode ( )
255=> throw new NotSupportedException();

◆ MoveNext()

bool SystemEx.FlexSpan< T >.MoveNext ( )

Moves to the next element in the span.

85 {
86 bool _ret = false;
87
88 if( HasNext ) {
89 m_index++;
90 if ( m_index < 0 ) m_index = 0;
91 _ret = true;
92 }
93 return _ret;
94 }

◆ operator!=()

bool SystemEx.FlexSpan< T >.operator!= ( FlexSpan< T > left,
FlexSpan< T > right )
static

Structural not equality comparison.

249=> !(left == right);
Here is the call graph for this function:

◆ operator==()

bool SystemEx.FlexSpan< T >.operator== ( FlexSpan< T > left,
FlexSpan< T > right )
static

Structural equality comparison.

239 =>
240 left.m_llength == right.m_llength &&
241 left.m_pReference.Equals(right.m_pReference) &&
242 left.m_eMode == right.m_eMode &&
243 left.m_lStart == right.m_lStart &&
244 left.m_lEnd == right.m_lEnd;
Here is the call graph for this function:

◆ Reset()

void IEnumerator. SystemEx.FlexSpan< T >.Reset ( )

Resets the enumerator to the initial position. Ring mode resets to index 0; other modes reset to -1.

114=> m_index = m_span.m_eMode == FlexSpanMode.Ring ? 0 : m_index = -1;

◆ Slice() [1/2]

FlexSpan< T > SystemEx.FlexSpan< T >.Slice ( int start,
FlexSpanMode? mode = null )

Creates a new FlexSpan starting at the given offset.

227 => new FlexSpan<T>(ref m_pReference!, m_lStart + start, m_llength - start, mode ?? m_eMode);
Here is the call graph for this function:

◆ Slice() [2/2]

FlexSpan< T > SystemEx.FlexSpan< T >.Slice ( int start,
int length,
FlexSpanMode? mode = null )

Creates a new FlexSpan with a given offset and length.

234 => new FlexSpan<T>(ref m_pReference!, m_lStart + start, length, mode ?? m_eMode);
Here is the call graph for this function:

◆ ToArray()

Collections.Generic.Vector< T > SystemEx.FlexSpan< T >.ToArray ( )

Copies the view into a new Array<T>.

266 {
267 if ( m_llength == 0 )
268 return new Collections.Generic.Vector<T>();
269
270 var destination = new Collections.Generic.Vector<T>( (int)(m_lEnd - m_lStart) );
271
272 for ( long i = m_lStart, j = 0 ; i < m_lEnd ; i++, j++ ) {
273 T _e = ElementAt(j);
274 destination[(int)j] = _e;
275#if DEBUG
276 Console.WriteLine("ToArray, i = {0} j = {1} {2} [{3} ... {4}]", i, j, _e , m_lStart, m_lEnd);
277#endif
278 }
279
280 return destination;
281 }
Here is the call graph for this function:

◆ TryCopyTo()

bool SystemEx.FlexSpan< T >.TryCopyTo ( FlexSpan< T > destination)

Attempts to copy the view into another FlexSpan.

296 {
297 bool _ret = false;
298 try {
299 CopyTo(destination);
300
301 _ret = true;
302 } catch(Exception ) {
303 _ret = false;
304 }
305 return _ret;
306 }
Here is the call graph for this function:

Property Documentation

◆ Current [1/3]

object IEnumerator. SystemEx.FlexSpan< T >.Current
get

◆ Current [2/3]

T IEnumerator<T>. SystemEx.FlexSpan< T >.Current
get

◆ Current [3/3]

ref T SystemEx.FlexSpan< T >.Current
get

Gets the element at the current enumerator position.

99 {
100 [MethodImpl(MethodImplOptions.AggressiveInlining)]
101 get => ref m_span[m_index];
102 }

◆ Empty

FlexSpan<T> SystemEx.FlexSpan< T >.Empty
staticget

Returns an empty FlexSpan.

◆ End

long SystemEx.FlexSpan< T >.End
get

End index of the view (exclusive).

◆ HasNext

bool SystemEx.FlexSpan< T >.HasNext
get

Indicates whether another element can be produced. Ring mode always returns true (infinite iteration).

59 {
60 [MethodImpl(MethodImplOptions.AggressiveInlining)]
61 get {
62 bool _ret = false;
63 if ( m_span.m_eMode == FlexSpanMode.Ring )
64 _ret = true;
65 else
66 _ret = (m_index + 1) < (m_span.m_lEnd - m_span.m_lStart);
67 return _ret;
68 }
69 }

◆ IsEmpty

bool SystemEx.FlexSpan< T >.IsEmpty
get

True if the span has zero length.

◆ Length

long SystemEx.FlexSpan< T >.Length
get

Total length of the underlying array.

◆ Start

long SystemEx.FlexSpan< T >.Start
get

Start index of the view.

◆ this[int index]

ref T SystemEx.FlexSpan< T >.this[int index]
get

Provides ref-access to the element at the given index within the view.

175 {
176 get => ref ElementAt(index);
177 }

◆ ViewLength

long SystemEx.FlexSpan< T >.ViewLength
get

Length of the view (End - Start).


The documentation for this struct was generated from the following file:
  • FlexSpan.cs