Enhanced C#
Language of your choice: library documentation
|
VList represents a reference to a reverse-order FVList. More...
VList represents a reference to a reverse-order FVList.
An article is available online about the VList data types.
The VList is a persistent list data structure described in Phil Bagwell's 2002 paper "Fast Functional Lists, Hash-Lists, Deques and Variable Length Arrays". Originally, this type was called RVList because it works in the reverse order to the original VList type: new items are normally added at the beginning of a VList, which is normal in functional languages, but this VList acts like a normal .NET list, so it is optimized for new items to be added at the end. The name "RVList" is ugly, though, since it misleadingly appears to be related to Recreational Vehicles. So as of LeMP 1.5, it's called simply VList.
In contrast, the FVList<T> type acts like the original VList; its Add method puts new items at the beginning (index 0).
See the remarks of VListBlock<T> for a more detailed description.
Nested classes | |
struct | Enumerator |
Enumerates through a VList from index 0 up to index Count-1. More... | |
Public static fields | |
static readonly VList< T > | Empty = new VList<T>() |
Properties | |
VList< T > | Tail [get] |
Returns a list without the last item. If the list is empty, an empty list is retured. More... | |
T | Last [get] |
Returns the last item of the list (at index Count-1), which is the head of the list. More... | |
bool | IsEmpty [get] |
int? | BlockChainLength [get] |
Gets the number of blocks used by this list. More... | |
T | this[int index] [get, set] |
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. More... | |
int | Count [get] |
bool | IsReadOnly [get] |
Properties inherited from Loyc.Collections.IPop< T > | |
bool | IsEmpty [get] |
Public Member Functions | |
VList (T firstItem) | |
VList (T itemZero, T itemOne) | |
VList (T[] array) | |
VList (IEnumerable< T > list) | |
VList (VList< T > list) | |
VList< T > | WithoutLast (int offset) |
VList< T > | NextIn (VList< T > largerList) |
VList< T > | First (int count) |
override bool | Equals (object rhs_) |
Returns whether the two list references are the same. Does not compare the contents of the lists. More... | |
override int | GetHashCode () |
VList< T > | AddRange (VList< T > list) |
VList< T > | AddRange (VList< T > list, VList< T > excludeSubList) |
VList< T > | AddRange (IReadOnlyList< T > list) |
VList< T > | AddRange (IEnumerable< T > list) |
VList< T > | InsertRange (int index, IReadOnlyList< T > list) |
VList< T > | RemoveRange (int index, int count) |
T | TryPop (out bool isEmpty) |
Removes the last item (at index Count-1) from the list and returns it. More... | |
T | TryPeek (out bool isEmpty) |
Gets the last item in the list (at index Count-1). More... | |
T | Pop () |
Removes the last item (at index Count-1) from the list and returns it. More... | |
VList< T > | Push (T item) |
Synonym for Add(); adds an item to the front of the list. More... | |
FVList< T > | ToFVList () |
Returns this list as a FVList, which effectively reverses the order of the elements. More... | |
FWList< T > | ToFWList () |
Returns this list as a FWList, which effectively reverses the order of the elements. More... | |
WList< T > | ToWList () |
Returns this list as an WList. More... | |
T[] | ToArray () |
Returns the VList converted to an array. More... | |
int | IndexOf (T item) |
Searches for the specified object and returns the zero-based index of the first occurrence (lowest index) within the entire VList. More... | |
void IList< T >. | Insert (int index, T item) |
VList< T > | Insert (int index, T item) |
void IList< T >. | RemoveAt (int index) |
VList< T > | RemoveAt (int index) |
void ICollection< T >. | Add (T item) |
Inserts an item at the back (index Count) of the VList. More... | |
VList< T > | Add (T item) |
Inserts an item at the back (index Count) of the VList. More... | |
void ICollection< T >. | Clear () |
VList< T > | Clear () |
bool | Contains (T item) |
void | CopyTo (T[] array, int arrayIndex) |
Copies the elements of the collection to an Array, starting at a particular array index. More... | |
bool | Remove (T item) |
Enumerator | GetEnumerator () |
IEnumerator< T > IEnumerable< T >. | GetEnumerator () |
System.Collections.IEnumerator System.Collections.IEnumerable. | GetEnumerator () |
T | TryGet (int index, out bool fail) |
IRange< T > IListSource< T >. | Slice (int start, int count) |
Slice_< T > | Slice (int start, int count=int.MaxValue) |
VList< T > | Clone () |
object ICloneable. | Clone () |
VList< T > | SmartWhere (Func< T, bool > keep) |
Applies a filter to a list, to exclude zero or more items. More... | |
VList< T > | WhereSelect (Func< T, Maybe< T >> filter) |
Filters and maps a list with a user-defined function. More... | |
VList< T > | SmartSelect (Func< T, T > map) |
Maps a list to another list of the same length. More... | |
VList< T > | SmartSelectMany (Func< T, IReadOnlyList< T >> map) |
Maps a list to another list by concatenating the outputs of a mapping function. More... | |
VList< T > | Transform (VListTransformer< T > x) |
Transforms a list (combines filtering with selection and more). More... | |
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... | |
Public Member Functions inherited from Loyc.Collections.IPop< T > | |
T | TryPop (out bool isEmpty) |
T | TryPeek (out bool isEmpty) |
Static Public Member Functions | |
static bool | operator== (VList< T > lhs, VList< T > rhs) |
Returns whether the two list references are the same. Does not compare the contents of the lists. More... | |
static bool | operator!= (VList< T > lhs, VList< T > rhs) |
Returns whether the two list references are different. Does not compare the contents of the lists. More... | |
static | operator FVList< T > (VList< T > list) |
Returns this list as a FVList, which effectively reverses the order of the elements. More... | |
static | operator FWList< T > (VList< T > list) |
Returns this list as a FWList, which effectively reverses the order of the elements. More... | |
static | operator WList< T > (VList< T > list) |
Returns this list as an WList. More... | |
|
inline |
Inserts an item at the back (index Count) of the VList.
Referenced by Loyc.Collections.VList< Loyc.Syntax.LNode >.Add(), and Loyc.Collections.VList< Loyc.Syntax.LNode >.Push().
|
inline |
Inserts an item at the back (index Count) of the VList.
|
inline |
Copies the elements of the collection to an Array, starting at a particular array index.
It's usually more convenient to call the ToArray() extension method, which calls this method for you.
This method exists for performance reasons (the collection itself can often copy data out faster than an enumerator can).
ArgumentNullException | array is null. |
ArgumentOutOfRangeException | arrayIndex is negative. |
ArgumentException | The number of elements in the source collection is greater than the available space from arrayIndex to the end of the destination array. |
Implements Loyc.Collections.ICollectionSource< T >.
|
inline |
Returns whether the two list references are the same. Does not compare the contents of the lists.
|
inline |
Searches for the specified object and returns the zero-based index of the first occurrence (lowest index) within the entire VList.
item | Item to locate (can be null if T can be null) |
This method determines equality using the default equality comparer EqualityComparer.Default for T, the type of values in the list.
This method performs a linear search, and is typically an O(n) operation, where n is Count. However, because the list is searched upward from index 0 to Count-1, if the list's blocks do not increase in size exponentially (due to the way that the list has been modified in the past), the search can have worse performance; the (unlikely) worst case is O(n^2). FVList(of T).IndexOf() doesn't have this problem.
|
inlineexplicitstatic |
|
inlineexplicitstatic |
|
inlineexplicitstatic |
|
inlinestatic |
Returns whether the two list references are different. Does not compare the contents of the lists.
|
inlinestatic |
Returns whether the two list references are the same. Does not compare the contents of the lists.
|
inline |
Removes the last item (at index Count-1) from the list and returns it.
|
inline |
Synonym for Add(); adds an item to the front of the list.
|
inline |
Maps a list to another list of the same length.
map | A function that transforms each item in the list. |
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, those N items are typically not copied, but shared between the existing list and the new one. This is useful for functional code that often processes a list without modifying it at all.
|
inline |
Maps a list to another list by concatenating the outputs of a mapping function.
map | A function that transforms each item in the list to a list of items. |
map
.This method is called "Smart" because of what happens if the map doesn't do anything. If, for the first N items, the map
returns a list of length 1, and that one item is the same item that was passed in, then those N items are typically not copied, but shared between the existing list and the new one. This is useful for functional code that often processes a list without modifying it at all.
|
inline |
Applies a filter to a list, to exclude zero or more items.
keep | A function that chooses which items to include (exclude items by returning false). |
If the predicate keeps the first N items it is passed, those N items are typically not copied, but shared between the existing list and the new one.
|
inline |
Returns the VList converted to an array.
|
inline |
|
inline |
Returns this list as a FWList, which effectively reverses the order of the elements.
The list contents are not copied until you modify the FWList.
Referenced by Loyc.Collections.VList< Loyc.Syntax.LNode >.operator FWList< T >().
|
inline |
Returns this list as an WList.
The list contents are not copied until you modify the WList.
Referenced by Loyc.Collections.VList< Loyc.Syntax.LNode >.operator WList< T >().
|
inline |
Transforms a list (combines filtering with selection and more).
x | Method to apply to each item in the list |
See the documentation of FVList.Transform() for more information.
Referenced by Loyc.Collections.VList< Loyc.Syntax.LNode >.WhereSelect().
|
inline |
Gets the last item in the list (at index Count-1).
isEmpty | When the list is empty, this is set to true and default(T) is returned. |
|
inline |
Removes the last item (at index Count-1) from the list and returns it.
isEmpty | When the list is empty, this is set to true and default(T) is returned. |
|
inline |
Filters and maps a list with a user-defined function.
filter | A function that chooses which items to include in a new list, and what to change them to. |
This is a smart function. If the filter keeps the first N items it is passed, those N items are typically not copied, but shared between the existing list and the new one.
|
get |
Gets the number of blocks used by this list.
You might look at this property when optimizing your program, because the runtime of some operations increases as the chain length increases. This property runs in O(BlockChainLength) time. Ideally, BlockChainLength is proportional to log_2(Count), but certain VList usage patterns can produce long chains.
|
get |
Returns the last item of the list (at index Count-1), which is the head of the list.
Referenced by Loyc.Collections.VList< Loyc.Syntax.LNode >.Pop(), Loyc.Collections.VList< Loyc.Syntax.LNode >.TryPeek(), and Loyc.Collections.VList< Loyc.Syntax.LNode >.TryPop().
|
get |
Returns a list without the last item. If the list is empty, an empty list is retured.
|
get |
Gets an item from the list at the specified index; returns defaultValue if the index is not valid.