Summary
Implements a variable-size list that uses a pooled array to store the
elements. A PooledList has a capacity, which is the allocated length
of the internal array. As elements are added to a PooledList, the capacity
of the PooledList is automatically increased as required by reallocating the
internal array.
- Namespace
- Avalonia
.Collections .Pooled - Interfaces
- Base Types
-
- object
graph BT
Type-->Base0["object"]
Type-.->Interface0["IList<T>"]
Type-.->Interface1["ICollection<T>"]
Type-.->Interface2["IReadOnlyPooledList<T>"]
Type-.->Interface3["IReadOnlyList<T>"]
Type-.->Interface4["IReadOnlyCollection<T>"]
Type-.->Interface5["IEnumerable<T>"]
Type-.->Interface6["IList"]
Type-.->Interface7["ICollection"]
Type-.->Interface8["IEnumerable"]
Type-.->Interface9["IDisposable"]
Type-.->Interface10["IDeserializationCallback"]
Type["PooledList<T>"]
class Type type-node
Syntax
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(ICollectionDebugView<>))]
[Serializable]
public class PooledList<T> : IList<T>, ICollection<T>, IReadOnlyPooledList<T>, IReadOnlyList<T>,
IReadOnlyCollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable, IDisposable,
IDeserializationCallback
Remarks
This class is based on the code for
List<T>
but it supports System.Span`1
and uses ArrayPool<T>
when allocating internal arrays.
Attributes
Type | Description |
---|---|
Debugger |
|
Debugger |
|
Serializable |
Type Parameters
Name | Description |
---|---|
T |
Constructors
Name | Summary |
---|---|
PooledList |
Constructs a PooledList. The list is initially empty and has a capacity of zero. Upon adding the first element to the list the capacity is increased to DefaultCapacity, and then increased in multiples of two as required. |
PooledList |
Constructs a PooledList. The list is initially empty and has a capacity of zero. Upon adding the first element to the list the capacity is increased to DefaultCapacity, and then increased in multiples of two as required. |
PooledList |
Constructs a PooledList. The list is initially empty and has a capacity of zero. Upon adding the first element to the list the capacity is increased to DefaultCapacity, and then increased in multiples of two as required. |
PooledList |
Constructs a PooledList. The list is initially empty and has a capacity of zero. Upon adding the first element to the list the capacity is increased to DefaultCapacity, and then increased in multiples of two as required. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a List with a given initial capacity. The list is initially empty, but will have room for the given number of elements before any reallocations are required. |
PooledList |
Constructs a List with a given initial capacity. The list is initially empty, but will have room for the given number of elements before any reallocations are required. |
PooledList |
Constructs a List with a given initial capacity. The list is initially empty, but will have room for the given number of elements before any reallocations are required. |
PooledList |
Constructs a List with a given initial capacity. The list is initially empty, but will have room for the given number of elements before any reallocations are required. |
PooledList |
Constructs a List with a given initial capacity. The list is initially empty, but will have room for the given number of elements before any reallocations are required. |
PooledList |
Constructs a List with a given initial capacity. The list is initially empty, but will have room for the given number of elements before any reallocations are required. |
PooledList |
Constructs a List with a given initial capacity. The list is initially empty, but will have room for the given number of elements before any reallocations are required. |
PooledList |
Constructs a List with a given initial capacity. The list is initially empty, but will have room for the given number of elements before any reallocations are required. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
PooledList |
Constructs a PooledList, copying the contents of the given collection. The size and capacity of the new list will both be equal to the size of the given collection. |
Properties
Name | Value | Summary |
---|---|---|
Capacity | int |
Gets and sets the capacity of this list. The capacity is the size of
the internal array used to hold items. When set, the internal
Memory of the list is reallocated to the given capacity.
Note that the return value for this property may be larger than the property was set to.
|
ClearMode | ClearMode |
Returns the ClearMode behavior for the collection, denoting whether values are
cleared from internal arrays before returning them to the pool.
|
Count | int |
Read-only property describing how many elements are in the List.
|
Span | Span |
Gets a
Span<T> for the items currently in the collection.
|
this[int] | T |
Gets or sets the element at the given index.
|
Methods
Name | Value | Summary |
---|---|---|
Add |
void |
Adds the given object to the end of this list. The size of the list is
increased by one. If required, the capacity of the list is doubled
before adding the new element.
|
AddRange |
void |
Adds the elements of the given collection to the end of this list. If
required, the capacity of the list is increased to twice the previous
capacity or the new size, whichever is larger.
|
AddRange |
void |
Adds the elements of the given
ReadOnlySpan<T> to the end of this list. If
required, the capacity of the list is increased to twice the previous
capacity or the new size, whichever is larger.
|
AddRange |
void |
Adds the elements of the given array to the end of this list. If
required, the capacity of the list is increased to twice the previous
capacity or the new size, whichever is larger.
|
AddSpan |
Span |
Advances the
Count by the number of items specified,
increasing the capacity if required, then returns a Span representing
the set of items to be added, allowing direct writes to that section
of the collection.
|
AsReadOnly |
ReadOnlyCollection |
|
BinarySearch |
int |
Searches a section of the list for a given element using a binary search
algorithm.
|
BinarySearch |
int |
Searches the list for a given element using a binary search
algorithm. If the item implements
System.IComparable`1
then that is used for comparison, otherwise System.Collections.Generic.Comparer`1.Default is used.
|
BinarySearch |
int |
Searches the list for a given element using a binary search
algorithm. If the item implements
System.IComparable`1
then that is used for comparison, otherwise System.Collections.Generic.Comparer`1.Default is used.
|
Clear |
void |
Clears the contents of the PooledList.
|
Contains |
bool |
Contains returns true if the specified element is in the List.
It does a linear, O(n) search. Equality is determined by calling
EqualityComparer{T}.Default.Equals.
|
ConvertAll |
PooledList |
|
CopyTo |
void |
Copies this list to the given span.
|
Dispose |
void |
Returns the internal buffers to the ArrayPool.
|
Exists |
bool | |
FindAll |
PooledList |
|
FindIndex |
int | |
FindIndex |
int | |
FindIndex |
int | |
FindLastIndex |
int | |
FindLastIndex |
int | |
FindLastIndex |
int | |
ForEach |
void | |
GetEnumerator |
PooledList |
Returns an enumerator for this list with the given
permission for removal of elements. If modifications made to the list
while an enumeration is in progress, the MoveNext and
GetObject methods of the enumerator will throw an exception.
|
GetRange |
Span |
Equivalent to PooledList.Span.Slice(index, count).
|
IndexOf |
int |
Returns the index of the first occurrence of a given value in
this list. The list is searched forwards from beginning to end.
|
IndexOf |
int |
Returns the index of the first occurrence of a given value in a range of
this list. The list is searched forwards, starting at index
index and ending at count number of elements.
|
IndexOf |
int |
Returns the index of the first occurrence of a given value in a range of
this list. The list is searched forwards, starting at index
index and upto count number of elements.
|
Insert |
void |
Inserts an element into this list at a given index. The size of the list
is increased by one. If required, the capacity of the list is doubled
before inserting the new element.
|
InsertRange |
void |
Inserts the elements of the given collection at a given index. If
required, the capacity of the list is increased to twice the previous
capacity or the new size, whichever is larger. Ranges may be added
to the end of the list by setting index to the List's size.
|
InsertRange |
void |
Inserts the elements of the given collection at a given index. If
required, the capacity of the list is increased to twice the previous
capacity or the new size, whichever is larger. Ranges may be added
to the end of the list by setting index to the List's size.
|
InsertRange |
void |
Inserts the elements of the given collection at a given index. If
required, the capacity of the list is increased to twice the previous
capacity or the new size, whichever is larger. Ranges may be added
to the end of the list by setting index to the List's size.
|
InsertSpan |
Span |
Advances the
Count by the number of items specified,
increasing the capacity if required, then returns a Span representing
the set of items to be added, allowing direct writes to that section
of the collection.
|
LastIndexOf |
int |
Returns the index of the last occurrence of a given value in a range of
this list. The list is searched backwards, starting at the end
and ending at the first element in the list.
|
LastIndexOf |
int |
Returns the index of the last occurrence of a given value in a range of
this list. The list is searched backwards, starting at index
index and ending at the first element in the list.
|
LastIndexOf |
int |
Returns the index of the last occurrence of a given value in a range of
this list. The list is searched backwards, starting at index
index and upto count elements
|
Remove |
bool | |
RemoveAll |
int |
This method removes all items which match the predicate.
The complexity is O(n).
|
RemoveAt |
void |
Removes the element at the given index. The size of the list is
decreased by one.
|
RemoveRange |
void |
Removes a range of elements from this list.
|
Reverse |
void |
Reverses the elements in this list.
|
Reverse |
void |
Reverses the elements in a range of this list. Following a call to this
method, an element in the range given by index and count
which was previously located at index i will now be located at
index index + (index + count - i - 1).
|
Sort |
void |
Sorts the elements in this list. Uses the default comparer and
Array.Sort.
|
Sort |
void | |
Sort |
void |
Sorts the elements in this list. Uses Array.Sort with the
provided comparer.
|
Sort |
void |
Sorts the elements in a section of this list. The sort compares the
elements to each other using the given IComparer interface. If
comparer is null, the elements are compared to each other using
the IComparable interface, which in that case must be implemented by all
elements of the list.
This method uses the Array.Sort method to sort the elements.
|
ToArray |
T[] |
ToArray returns an array containing the contents of the List.
This requires copying the List, which is an O(n) operation.
|
TrimExcess |
void |
Sets the capacity of this list to the size of the list. This method can
be used to minimize a list's memory overhead once it is known that no
new elements will be added to the list. To completely clear a list and
release all memory referenced by the list, execute the following
statements:
|
TrueForAll |
bool | |
TryFind |
bool | |
TryFindLast |
bool |