Enhanced C#
Language of your choice: library documentation
Properties | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Loyc.Collections.FWList< T > Class Template Reference

FWList is the mutable variant of the FVList data structure. More...


Source file:
Inheritance diagram for Loyc.Collections.FWList< T >:
Loyc.Collections.WListBase< T > Loyc.Collections.IListAndListSource< T > Loyc.ICloneable< out out T > Loyc.Collections.WListProtected< T > Loyc.Collections.IListAndListSource< T > Loyc.Collections.IListAndReadOnly< T > Loyc.Collections.IListSource< T > Loyc.Collections.ICollectionAndSource< T > Loyc.Collections.ICollectionAndReadOnly< T > Loyc.Collections.ICollectionSource< T > Loyc.Collections.ICollectionAndReadOnly< T > Loyc.Collections.ICollectionAndSource< T > Loyc.Collections.IListSource< T > Loyc.Collections.IListAndReadOnly< T >

Remarks

FWList is the mutable variant of the FVList data structure.

An article is available online about the VList data types.

See the remarks of VListBlock<T> for more information about VLists and WLists. It is most efficient to add items to the front of a FWList (at index 0) or the back of an WList (at index Count-1).

Properties

new T this[int index] [get, set]
 
this[int index, T defaultValue] [get]
 Gets an item from the list at the specified index; returns defaultValue if the index is not valid. More...
 
First [get]
 Returns the front item of the list (at index 0). More...
 
bool IsEmpty [get]
 
- Properties inherited from Loyc.Collections.WListBase< T >
this[int index] [get, set]
 
new int Count [get]
 
bool IsReadOnly [get]
 
new int BlockChainLength [get]
 
- Properties inherited from Loyc.Collections.WListProtected< T >
byte UserByte [get, set]
 An additional byte that the derived class can optionally use. More...
 
int? BlockChainLength [get]
 Gets the number of blocks used by this list. More...
 

Public Member Functions

 FWList (int initialSize)
 
 FWList (T itemZero, T itemOne)
 
 FWList (IReadOnlyList< T > list)
 
void AddRange (IReadOnlyList< T > list)
 
void InsertRange (int index, IReadOnlyList< T > list)
 
void RemoveRange (int index, int count)
 
new void Insert (int index, T item)
 
new void RemoveAt (int index)
 
new FVList< T >.Enumerator GetEnumerator ()
 
VList< T >.Enumerator ReverseEnumerator ()
 
new T TryGet (int index, out bool fail)
 
FWList< T > Clone ()
 
FWList< T > SmartWhere (Func< T, bool > keep)
 Applies a filter to a list, to exclude zero or more items. More...
 
FWList< T > WhereSelect (Func< T, Maybe< T >> filter)
 Filters and maps a list with a user-defined function. More...
 
FWList< T > SmartSelect (Func< T, T > map)
 Maps a list to another list of the same length. More...
 
FWList< T > Transform (VListTransformer< T > x)
 Transforms a list (combines filtering with selection and more). More...
 
Pop ()
 Removes the front item (at index 0) from the list and returns it. More...
 
FVList< T > WithoutFirst (int numToRemove)
 
WList< T > ToWList ()
 Returns this list as an WList, which effectively reverses the order of the elements. More...
 
T[] ToArray ()
 Returns the FWList converted to an array. More...
 
- Public Member Functions inherited from Loyc.Collections.WListBase< T >
new void Add (T item)
 
new void Clear ()
 
new void Insert (int index, T item)
 
new void RemoveAt (int index)
 
new int IndexOf (T item)
 
new bool Contains (T item)
 
new void CopyTo (T[] array, int arrayIndex)
 Copies the elements of the collection to an Array, starting at a particular array index. More...
 
new bool Remove (T item)
 
IEnumerator< T > GetEnumerator ()
 
TryGet (int index, out bool fail)
 
Slice_< T > Slice (int start, int count)
 
void Push (T item)
 Synonym for Add(); adds an item to the front of the list. More...
 
new FVList< T > ToFVList ()
 
new VList< T > ToVList ()
 
- Public Member Functions inherited from Loyc.Collections.IListSource< T >
IRange< T > Slice (int start, int count=int.MaxValue)
 Returns a sub-range of this list. More...
 
- Public Member Functions inherited from Loyc.Collections.IContains< T >
bool Contains (T item)
 Returns true if and only if the collection contains the specified item. More...
 

Static Public Member Functions

static operator WList< T > (FWList< T > list)
 Returns this list as an WList, which effectively reverses the order of the elements. More...
 
- Static Public Member Functions inherited from Loyc.Collections.WListBase< T >
static operator FVList< T > (WListBase< T > list)
 Returns this list as a FVList; if this is a WList, the order of the elements is reversed at the same time. More...
 
static operator VList< T > (WListBase< T > list)
 Returns this list as a VList; if this is a FWList, the order of the elements is reversed at the same time. More...
 

Protected Member Functions

override int AdjustWListIndex (int index, int size)
 This method implements the difference between FWList and WList: In FWList it returns index, but in WList it returns Count-size-index. More...
 
override IEnumerator< T > GetIEnumerator ()
 
- Protected Member Functions inherited from Loyc.Collections.WListProtected< T >
 WListProtected (WListProtected< T > original, bool takeOwnership)
 
GetAt (int index)
 Gets an item from a FWList or WList at the specified index. More...
 
void SetAt (int index, T value)
 Sets an item in a FWList or WList at the specified index. More...
 
void Add (T item)
 Inserts an item at the "front" of the list, which is index 0 for FWList, or Count for WList. More...
 
void Insert (int index, T item)
 
void RemoveAt (int index)
 
int IndexOf (T item)
 Searches for the specified object and returns the zero-based index of the first occurrence (lowest index) within the entire FVList. More...
 
bool Contains (T item)
 
void CopyTo (T[] array, int arrayIndex)
 
bool Remove (T item)
 
FVList< T >.Enumerator GetVListEnumerator ()
 
VList< T >.Enumerator GetRVListEnumerator ()
 
void RemoveAtDff (int distanceFromFront)
 
void RemoveRangeBase (int distanceFromFront, int count)
 
void InsertRangeAtDff (int distanceFromFront, IReadOnlyList< T > items, bool isRWList)
 
void InsertAtDff (int distanceFromFront, T item)
 
GetAtDff (int distanceFromFront)
 Gets an item WITHOUT doing a range check More...
 
void SetAtDff (int distanceFromFront, T item)
 Sets an item WITHOUT doing a range or mutability check More...
 
FVList< T > ToFVList ()
 Returns this list as a FVList; if this is a WList, the order of the elements is reversed at the same time. More...
 
VList< T > ToVList ()
 Returns this list as a VList; if this is a FWList, the order of the elements is reversed at the same time. More...
 

Member Function Documentation

◆ AdjustWListIndex()

override int Loyc.Collections.FWList< T >.AdjustWListIndex ( int  index,
int  size 
)
inlineprotectedvirtual

This method implements the difference between FWList and WList: In FWList it returns index, but in WList it returns Count-size-index.

Parameters
indexIndex to adjust
sizeNumber of elements being accessed or removed

Solely as an optimization, FWList and WList also have separate versions of this[], InsertAt and RemoveAt.

Reimplemented from Loyc.Collections.WListProtected< T >.

◆ operator WList< T >()

static Loyc.Collections.FWList< T >.operator WList< T > ( FWList< T >  list)
inlineexplicitstatic

Returns this list as an WList, which effectively reverses the order of the elements.

This operation marks the items of the list as immutable. You can modify either list afterward, but some or all of the list may have to be copied.

References Loyc.Collections.FWList< T >.ToWList().

◆ Pop()

T Loyc.Collections.FWList< T >.Pop ( )
inline

Removes the front item (at index 0) from the list and returns it.

References Loyc.Collections.FWList< T >.First.

◆ SmartSelect()

FWList<T> Loyc.Collections.FWList< T >.SmartSelect ( Func< T, T >  map)
inline

Maps a list to another list of the same length.

Parameters
mapA function that transforms each item in the list.
Returns
The list after the map function is applied to each item. The original VList structure is not modified.

This method is called "Smart" because of what happens if the map doesn't do anything. If the map function returns the first N items unmodified (the items at the tail of the FWList), those N items are typically not copied, but shared between the existing list and the new one.

◆ SmartWhere()

FWList<T> Loyc.Collections.FWList< T >.SmartWhere ( Func< T, bool >  keep)
inline

Applies a filter to a list, to exclude zero or more items.

Parameters
keepA function that chooses which items to include (exclude items by returning false).
Returns
The list after filtering has been applied. The original VList structure is not modified.

If the predicate keeps the first N items it is passed (which are the last or "tail" items in a FWList), those N items are typically not copied, but shared between the existing list and the new one.

◆ ToArray()

T [] Loyc.Collections.FWList< T >.ToArray ( )
inline

Returns the FWList converted to an array.

References Loyc.Collections.VListBlock< T >.ToArray().

◆ ToWList()

WList<T> Loyc.Collections.FWList< T >.ToWList ( )
inline

Returns this list as an WList, which effectively reverses the order of the elements.

This operation marks the items of the list as immutable. You can modify either list afterward, but some or all of the list may have to be copied.

References Loyc.Collections.VListBlock< T >.EnsureImmutable().

Referenced by Loyc.Collections.FWList< T >.operator WList< T >().

◆ Transform()

FWList<T> Loyc.Collections.FWList< T >.Transform ( VListTransformer< T >  x)
inline

Transforms a list (combines filtering with selection and more).

Parameters
xMethod to apply to each item in the list
Returns
A list formed from transforming all items in the list

See the documentation of FVList.Transform() for more information.

References Loyc.Collections.VListBlock< T >.Transform().

Referenced by Loyc.Collections.FWList< T >.WhereSelect().

◆ WhereSelect()

FWList<T> Loyc.Collections.FWList< T >.WhereSelect ( Func< T, Maybe< T >>  filter)
inline

Filters and maps a list with a user-defined function.

Parameters
filterA function that chooses which items to include in a new list, and what to change them to.
Returns
The list after filtering has been applied. The original list structure is not modified.

This is a smart function. If the filter does not modify the first N items it is passed (which are the last items in a FWList), those N items are typically not copied, but shared between the existing list and the new one.

References Loyc.Collections.FWList< T >.Transform().

Property Documentation

◆ First

T Loyc.Collections.FWList< T >.First
get

Returns the front item of the list (at index 0).

Referenced by Loyc.Collections.FWList< T >.Pop().

◆ this[int index, T defaultValue]

T Loyc.Collections.FWList< T >.this[int index, T defaultValue]
get

Gets an item from the list at the specified index; returns defaultValue if the index is not valid.