Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public static fields | Properties | Public Member Functions | Static Public Member Functions | List of all members
Loyc.Collections.NegListSource< T > Struct Template Reference

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


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

Remarks

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

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

Like ListSourceSlice, this structure provides a view of another list starting at a certain offset. Unlike ListSourceSlice, however, this structure allows the caller to access the entire original list, not just a slice.

Public static fields

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

Properties

IListSource< 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]
 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.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...
 
this[int index] [get]
 Gets the item at the specified index. More...
 

Public Member Functions

 NegListSource (IListSource< T > list, int zeroOffset)
 Initializes a NegListSource wrapper. More...
 
TryGet (int index, out bool fail)
 Gets the item at the specified index, and does not throw an exception on failure.
Parameters
indexAn index in the range Min to Max.
failA flag that is set on failure. To improve performance slightly, this flag is not cleared on success.
Returns
The element at the specified index, or default(T) if the index is not valid.
In my original design, the caller could provide a value to return on failure, but this would not allow T to be marked as "out" in C# 4. For the same reason, we cannot have a ref/out T parameter. Instead, the following extension methods are provided:

bool TryGet(int index, ref T value);
T TryGet(int, T defaultValue);

 
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 (NegListSource< T > rhs)
 
override bool Equals (object obj)
 
override int GetHashCode ()
 
override string ToString ()
 Returns ToString() of the wrapped list. More...
 

Static Public Member Functions

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

Constructor & Destructor Documentation

Loyc.Collections.NegListSource< T >.NegListSource ( IListSource< 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. For example, if zeroOffset==-1, this object will have Min==1 and Max==Count.

Member Function Documentation

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

Returns a sub-range of this list.

Implements Loyc.Collections.INegListSource< T >.

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

Returns ToString() of the wrapped list.

Property Documentation

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

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

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

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

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

Returns the minimum valid index.

int Loyc.Collections.NegListSource< 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.

IListSource<T> Loyc.Collections.NegListSource< T >.OriginalList
get

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

T Loyc.Collections.NegListSource< T >.this[int index]
get

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.