Class FastList<T>
List<T> implementation that let you access to the internal array.
Inherited Members
Namespace: Evergine.Common.Collections
Assembly: Evergine.Common.dll
Syntax
public class FastList<T> : IList<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, ICollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The elements type. |
Constructors
FastList()
Initializes a new instance of the FastList<T> class.
Declaration
public FastList()
FastList(IEnumerable<T>)
Initializes a new instance of the FastList<T> class.
Declaration
public FastList(IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | collection | The item collection. |
FastList(int)
Initializes a new instance of the FastList<T> class.
Declaration
public FastList(int capacity)
Parameters
Type | Name | Description |
---|---|---|
int | capacity | The list capacity. |
Properties
Capacity
Gets or sets the list capacity.
Declaration
public int Capacity { get; set; }
Property Value
Type | Description |
---|---|
int |
Count
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
this[int]
Declaration
public T this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index |
Property Value
Type | Description |
---|---|
T |
Items
Gets the items.
Declaration
public T[] Items { get; }
Property Value
Type | Description |
---|---|
T[] |
Methods
Add(T)
Declaration
public void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
AddRange(IEnumerable<T>)
Adds a collection of elements to the list.
Declaration
public void AddRange(IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | collection | The collection to be added. |
AsReadOnly()
Returns the list as a ReadOnlyCollection.
Declaration
public ReadOnlyCollection<T> AsReadOnly()
Returns
Type | Description |
---|---|
ReadOnlyCollection<T> | The ReadOnlyCollection object containing the items of the list. |
BinarySearch(int, int, T, IComparer<T>)
Searches an item through the binary search method.
Declaration
public int BinarySearch(int index, int count, T item, IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
int | index | The starting index of the range to search. |
int | count | The length of the range to search. |
T | item | The object to search for. |
IComparer<T> | comparer | The comparer implementation to use when comparing elements. -or- null to use the comparable implementation of each element. |
Returns
Type | Description |
---|---|
int | The index of the specified value in the specified array, if value is found; otherwise, a negative number. |
BinarySearch(T)
Searches an item through the binary search method.
Declaration
public int BinarySearch(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to search for. |
Returns
Type | Description |
---|---|
int | The index of the specified value in the specified array, if value is found; otherwise, a negative number. |
BinarySearch(T, IComparer<T>)
Searches an item through the binary search method.
Declaration
public int BinarySearch(T item, IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to search for. |
IComparer<T> | comparer | The comparer implementation to use when comparing elements. -or- null to use the comparable implementation of each element. |
Returns
Type | Description |
---|---|
int | The index of the specified value in the specified array, if value is found; otherwise, a negative number. |
Clear()
Declaration
public void Clear()
Clear(bool)
Clears this list with a fast-clear option.
Declaration
public void Clear(bool fastClear)
Parameters
Type | Name | Description |
---|---|---|
bool | fastClear | if set to |
Contains(T)
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
Returns
Type | Description |
---|---|
bool |
CopyTo(int, T[], int, int)
Copies the elements of this list to another array.
Declaration
public void CopyTo(int index, T[] array, int arrayIndex, int count)
Parameters
Type | Name | Description |
---|---|---|
int | index | The starting index of this list. |
T[] | array | The destination array where the elements will be copied. |
int | arrayIndex | The starting index of the destination array. |
int | count | The amount of elements to be copied. |
CopyTo(T[])
Copies the elements of this list to another array.
Declaration
public void CopyTo(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The destination array where the elements of this list will be copied. |
CopyTo(T[], int)
Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | |
int | arrayIndex |
EnsureCapacity(int)
Increases the list capacity ensuring the minimum size provided.
Declaration
public void EnsureCapacity(int min)
Parameters
Type | Name | Description |
---|---|---|
int | min | The minimum capacity. |
Exists(Predicate<T>)
Checks if the list contains an item that satisfies the predicate.
Declaration
public bool Exists(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
bool | True if exists an element that matches the predicate. False otherwise. |
Find(Predicate<T>)
Finds the first item of this list that matches a predicate.
Declaration
public T Find(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | The predicate to match. |
Returns
Type | Description |
---|---|
T | The item that matches the predicate. The default value otherwise. |
FindAll(Predicate<T>)
Finds all the items of this list that matches a predicate.
Declaration
public FastList<T> FindAll(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | The predicate to match. |
Returns
Type | Description |
---|---|
FastList<T> | A FastList containing the items that matches the predicate. |
FindIndex(int, int, Predicate<T>)
Finds the index of the first item of the list that matches the predicate.
Declaration
public int FindIndex(int startIndex, int count, Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
int | startIndex | The start index to search. |
int | count | The number of elements to search. |
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
int | The index of the match item if exists. A negative value otherwise. |
FindIndex(int, Predicate<T>)
Finds the index of the first item of the list that matches the predicate.
Declaration
public int FindIndex(int startIndex, Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
int | startIndex | The start index to search. |
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
int | The index of the match item if exists. A negative value otherwise. |
FindIndex(Predicate<T>)
Finds the index of the first item of the list that matches the predicate.
Declaration
public int FindIndex(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
int | The index of the match item if exists. A negative value otherwise. |
FindLast(Predicate<T>)
Finds the last item of this list that matches the predicate.
Declaration
public T FindLast(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
T | The last item that matches the predicate.Its default value otherwise. |
FindLastIndex(int, int, Predicate<T>)
Finds the index of the last item of this list that matches the predicate.
Declaration
public int FindLastIndex(int startIndex, int count, Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
int | startIndex | The start index for the search. |
int | count | The number of items for the search. |
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
int | The index of the last item that matches the predicate if it exists. A negative value otherwise. |
FindLastIndex(int, Predicate<T>)
Finds the index of the last item of this list that matches the predicate.
Declaration
public int FindLastIndex(int startIndex, Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
int | startIndex | The start index for the search. |
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
int | The index of the last item that matches the predicate if it exists. A negative value otherwise. |
FindLastIndex(Predicate<T>)
Finds the index of the last item of this list that matches the predicate.
Declaration
public int FindLastIndex(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
int | The index of the last item that matches the predicate if it exists. A negative value otherwise. |
ForEach(Action<T>)
Executes an action for each item of this list.
Declaration
public void ForEach(Action<T> action)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | action | The action to be executed per element. |
GetEnumerator()
Gets the list enumerator.
Declaration
public FastList<T>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
FastList<T>.Enumerator | The list enumerator. |
GetRange(int, int)
Gets another FastList containing a range of the elements of this list.
Declaration
public FastList<T> GetRange(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
int | index | The start index. |
int | count | The range size. |
Returns
Type | Description |
---|---|
FastList<T> | A FastList containing a range of the elements of this list. |
IncreaseCapacity(int)
Increases this list capacity.
Declaration
public void IncreaseCapacity(int amount)
Parameters
Type | Name | Description |
---|---|---|
int | amount | The amount to be increased. |
IndexOf(T)
Declaration
public int IndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
Returns
Type | Description |
---|---|
int |
IndexOf(T, int)
Gets the index of an item in this list, starting in a specified index.
Declaration
public int IndexOf(T item, int index)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to search. |
int | index | The start index. |
Returns
Type | Description |
---|---|
int | The index of the item if it exists in the list. A negative value otherwise. |
IndexOf(T, int, int)
Gets the index of an item in this list, starting in a specified index.
Declaration
public int IndexOf(T item, int index, int count)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to search. |
int | index | The start index. |
int | count | The number of elements to search. |
Returns
Type | Description |
---|---|
int | The index of the item if it exists in the list. A negative value otherwise. |
Insert(int, T)
Declaration
public void Insert(int index, T item)
Parameters
Type | Name | Description |
---|---|---|
int | index | |
T | item |
InsertRange(int, IEnumerable<T>)
Inserts a collection of items in this list in a specified index.
Declaration
public void InsertRange(int index, IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the insertion. |
IEnumerable<T> | collection | The item collection. |
LastIndexOf(T)
Gets the last index of an item in this list.
Declaration
public int LastIndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to be searched. |
Returns
Type | Description |
---|---|
int | The index of the last item if it exists in the list. A negative value otherwise. |
LastIndexOf(T, int)
Gets the last index of an item in this list.
Declaration
public int LastIndexOf(T item, int index)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to be searched. |
int | index | The start index. |
Returns
Type | Description |
---|---|
int | The index of the last item if it exists in the list. A negative value otherwise. |
LastIndexOf(T, int, int)
Gets the last index of an item in this list.
Declaration
public int LastIndexOf(T item, int index, int count)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to be searched. |
int | index | The start index. |
int | count | The number of elements of the search. |
Returns
Type | Description |
---|---|
int | The index of the last item if it exists in the list. A negative value otherwise. |
Remove(T)
Declaration
public bool Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
Returns
Type | Description |
---|---|
bool |
RemoveAll(Predicate<T>)
Remove all the elements of this array that match the predicate.
Declaration
public int RemoveAll(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
int | The number of items removed. |
RemoveAt(int)
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index |
RemoveRange(int, int)
Removes a range of items of this list.
Declaration
public void RemoveRange(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
int | index | The start index to remove. |
int | count | The number of items to remove. |
Resize(int, bool)
Resizes this list.
Declaration
public void Resize(int newSize, bool fastClear)
Parameters
Type | Name | Description |
---|---|---|
int | newSize | The new list size. |
bool | fastClear | If we don't want to clear the inner array when resizing. |
Reverse()
Reverses this list.
Declaration
public void Reverse()
Reverse(int, int)
Reverses a range of the list.
Declaration
public void Reverse(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
int | index | The start index. |
int | count | The number of elements for the operation. |
Sort()
Sorts the list.
Declaration
public void Sort()
Sort(IComparer<T>)
Sorts the list.
Declaration
public void Sort(IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
IComparer<T> | comparer | The comparer used for the operation. |
Sort(int, int, IComparer<T>)
Sorts the list.
Declaration
public void Sort(int index, int count, IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
int | index | The start item of the sort range. |
int | count | The number of items of the range to be sorted. |
IComparer<T> | comparer | The comparer used for the sorting. |
ToArray()
Gets the list as array.
Declaration
public T[] ToArray()
Returns
Type | Description |
---|---|
T[] | A new array containing all the items of the list. |
TrimExcess()
Adjusts the capacity of the list to its current size.
Declaration
public void TrimExcess()
TrueForAll(Predicate<T>)
Checks if all the items of the list match a predicate.
Declaration
public bool TrueForAll(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | The predicate to be match. |
Returns
Type | Description |
---|---|
bool | True if all the items of the list matches the predicate. False otherwise. |