Enhanced C#
Language of your choice: library documentation
Public static fields | Properties | Public Member Functions | Static Public Member Functions | List of all members
Loyc.Collections.NegList< T > Struct Template Reference

Adapter: provides a view of an IList<T> in which the Count is the same, but the minimum index is not necessarily zero. Returned from LCExt.AsNegList<T>(IListSource<T>,int). More...


Source file:
Inheritance diagram for Loyc.Collections.NegList< T >:
Loyc.Collections.INegArray< T > Loyc.Collections.INegListSource< T >

Remarks

Adapter: provides a view of an IList<T> in which the Count is the same, but the minimum index is not necessarily zero. Returned from LCExt.AsNegList<T>(IListSource<T>,int).

This wrapper is a structure in order to offer high performance in certain scenarios.

Public static fields

static readonly NegList< T > Empty = new NegList<T>(EmptyList<T>.Value, 0)
 

Properties

IList< T > OriginalList [get]
 Gets the list that was passed to the constructor of this instance. More...
 
int Offset [get, set]
 Returns the offset added to indexes in the original list, which equals -Min. More...
 
int Count [get]
 Returns the total number of items in the list (same as OriginalList.Count). More...
 
int Min [get]
 Returns the minimum valid index. More...
 
int Max [get]
 Returns the maximum valid index, which is Min + OriginalList.Count - 1. More...
 
this[int index] [get, set]
 Gets the value of the list at the specified index. In terms of the original list, this is OriginalList[index + Offset] More...
 
- Properties inherited from Loyc.Collections.INegArray< T >
new T this[int index] [get, set]
 Gets or sets an element of the array-like collection. More...
 
- Properties inherited from Loyc.Collections.INegListSource< T >
int Min [get]
 Returns the minimum valid index in the collection. More...
 
int Max [get]
 Returns the maximum valid index in the collection. More...
 

Public Member Functions

 NegList (IList< T > list, int zeroOffset)
 Initializes a NegListSource wrapper. More...
 
TryGet (int index, out bool fail)
 
bool TrySet (int index, T value)
 
IRange< T > Slice (int start, int count=int.MaxValue)
 Returns a sub-range of this list. More...
 
IEnumerator< T > GetEnumerator ()
 
System.Collections.IEnumerator System.Collections.IEnumerable. GetEnumerator ()
 
bool Equals (NegList< T > rhs)
 
override bool Equals (object obj)
 
override int GetHashCode ()
 
override string ToString ()
 Returns ToString() of the wrapped list. More...
 
- Public Member Functions inherited from Loyc.Collections.INegListSource< T >
IRange< T > Slice (int start, int count=int.MaxValue)
 Returns a sub-range of this list. More...
 

Static Public Member Functions

static bool operator== (NegList< T > a, NegList< T > b)
 
static bool operator!= (NegList< T > a, NegList< T > b)
 

Constructor & Destructor Documentation

◆ NegList()

Loyc.Collections.NegList< T >.NegList ( IList< T >  list,
int  zeroOffset 
)
inline

Initializes a NegListSource wrapper.

Parameters
listA list to wrap (must not be null).
zeroOffsetAn index into the original list. this[0] will refer to that index.

The zeroOffset can be any integer, but if it is not in the range 0 to list.Count-1, this[0] will not be valid.

Member Function Documentation

◆ Slice()

IRange<T> Loyc.Collections.NegList< T >.Slice ( int  start,
int  count = int.MaxValue 
)
inline

Returns a sub-range of this list.

◆ ToString()

override string Loyc.Collections.NegList< T >.ToString ( )
inline

Returns ToString() of the wrapped list.

Property Documentation

◆ Count

int Loyc.Collections.NegList< T >.Count
get

Returns the total number of items in the list (same as OriginalList.Count).

◆ Max

int Loyc.Collections.NegList< T >.Max
get

Returns the maximum valid index, which is Min + OriginalList.Count - 1.

◆ Min

int Loyc.Collections.NegList< T >.Min
get

Returns the minimum valid index.

◆ Offset

int Loyc.Collections.NegList< T >.Offset
getset

Returns the offset added to indexes in the original list, which equals -Min.

The 0th item in this list the same as OriginalList[Offset].

WARNING: this is a value type. Calling the setter may have unexpected consequences for people unfamiliar with the .NET type system, because it is easy to make copies accidentally, and changing the Offset in a copy does not change the Offset in the original.

◆ OriginalList

IList<T> Loyc.Collections.NegList< T >.OriginalList
get

Gets the list that was passed to the constructor of this instance.

◆ this[int index]

T Loyc.Collections.NegList< T >.this[int index]
getset

Gets the value of the list at the specified index. In terms of the original list, this is OriginalList[index + Offset]

Parameters
indexAn index in the range Min to Max.
Exceptions
ArgumentOutOfRangeExceptionThe index provided is not valid in this list.