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.
|
| 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 (IList< T > list) |
|
VList< T > | AddRange (IEnumerable< T > list) |
|
VList< T > | InsertRange (int index, IList< T > list) |
|
VList< T > | RemoveRange (int index, int count) |
|
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) |
|
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) |
| Gets the item at the specified index, and does not throw an exception on failure. More...
|
|
IRange< T > IListSource< T >. | Slice (int start, int count) |
| Returns a sub-range of this list. More...
|
|
Slice_< T > | Slice (int start, int count=int.MaxValue) |
| Returns a sub-range of this list. More...
|
|
VList< T > | Clone () |
|
object ICloneable. | Clone () |
|
VList< T > | Where (Predicate< T > 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< Out > | Select< Out > (Func< T, Out > map) |
| Maps a list to another list of the same length. More...
|
|
VList< T > | Transform (VListTransformer< T > x) |
| Transforms a list (combines filtering with selection and more). More...
|
|
|
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...
|
|
int Loyc.Collections.VList< T >.IndexOf |
( |
T |
item | ) |
|
|
inline |
Searches for the specified object and returns the zero-based index of the first occurrence (lowest index) within the entire VList.
- Parameters
-
item | Item to locate (can be null if T can be null) |
- Returns
- Index of the item, or -1 if it was not found.
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.
IRange<T> IListSource<T>. Loyc.Collections.VList< T >.Slice |
( |
int |
start, |
|
|
int |
count |
|
) |
| |
|
inline |
Returns a sub-range of this list.
- Parameters
-
start | The new range will start at this index in the current list (this location will be index [0] in the new range). |
count | The desired number of elements in the new range, or int.MaxValue to get all elements until the end of the list. |
- Returns
- Returns a sub-range of this range.
- Exceptions
-
ArgumentException | The start index was below zero. |
The (start, count) range is allowed to be invalid, as long as start is zero or above.
-
If count is below zero, or if start is above the original Count, the Count of the new slice is set to zero.
-
if (start + count) is above the original Count, the Count of the new slice is reduced to
this.Count - start
. Implementation note: do not compute (start + count) because it may overflow. Instead, test whether (count > this.Count - start).
Most collections should use the following implementation:
IRange<T> IListSource<T>.Slice(int start, int count) { return Slice(start, count); }
public Slice_<T> Slice(int start, int count) { return new Slice_<T>(this, start, count); }
Implements Loyc.Collections.IListSource< out T >.
References Loyc.Collections.VList< T >.Slice().
Referenced by Loyc.Collections.VList< T >.Slice().
Slice_<T> Loyc.Collections.VList< T >.Slice |
( |
int |
start, |
|
|
int |
count = int.MaxValue |
|
) |
| |
|
inline |
Returns a sub-range of this list.
- Parameters
-
start | The new range will start at this index in the current list (this location will be index [0] in the new range). |
count | The desired number of elements in the new range, or int.MaxValue to get all elements until the end of the list. |
- Returns
- Returns a sub-range of this range.
- Exceptions
-
ArgumentException | The start index was below zero. |
The (start, count) range is allowed to be invalid, as long as start is zero or above.
-
If count is below zero, or if start is above the original Count, the Count of the new slice is set to zero.
-
if (start + count) is above the original Count, the Count of the new slice is reduced to
this.Count - start
. Implementation note: do not compute (start + count) because it may overflow. Instead, test whether (count > this.Count - start).
Most collections should use the following implementation:
IRange<T> IListSource<T>.Slice(int start, int count) { return Slice(start, count); }
public Slice_<T> Slice(int start, int count) { return new Slice_<T>(this, start, count); }
Implements Loyc.Collections.IListSource< out T >.
T Loyc.Collections.VList< T >.TryGet |
( |
int |
index, |
|
|
out bool |
fail |
|
) |
| |
|
inline |
Gets the item at the specified index, and does not throw an exception on failure.
- Parameters
-
index | An index in the range 0 to Count-1. |
fail | A flag that is set on failure. |
- 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);
Implements Loyc.Collections.IListSource< out T >.