Struct PooledList<T>
A version of List<T> which uses an array pool.
For efficiency, PooledList<T> is implemented as a mutable struct. It's intended to be passed by reference.
Implements
- IDisposable
- IList<T>
- ICollection<T>
- IEnumerable<T>
- IEnumerable
Inherited Members
- ValueType.Equals(object)
- ValueType.GetHashCode()
- ValueType.ToString()
- object.GetType()
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
Declaration
public struct PooledList<T> : IDisposable, IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T |
The type of elements of the list. |
Constructors
PooledList(ArrayPool<T>)
Creates a PooledList<T> which uses the supplied ArrayPool<T>.
Declaration
public PooledList(ArrayPool<T> arrayPool)
Parameters
Type | Name | Description |
---|---|---|
ArrayPool<T> |
arrayPool |
The array pool. |
Properties
Count
The number of elements in the list.
Declaration
public readonly int Count { get; }
Property Value
Type | Description |
---|---|
IsReadOnly
Returns false.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
False. |
this[int]
Gets or sets the element at index index
.
Declaration
public T this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
index |
The index. |
Property Value
Type | Description |
---|---|
T |
The element at index |
Methods
Add(T)
Adds an item to the end of the list.
Declaration
public void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T |
item |
The item to add. |
AddRange(ICollection<T>)
Adds a collection of items to the end of the list.
Declaration
public void AddRange(ICollection<T> items)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> |
items |
The items to add. |
AddRange(IEnumerable<T>)
Adds a collection of items to the end of the list.
Declaration
public void AddRange(IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> |
items |
The items to add. |
AddRange(ImmutableArray<T>)
Adds a collection of items to the end of the list.
Declaration
public void AddRange(ImmutableArray<T> items)
Parameters
Type | Name | Description |
---|---|---|
items |
The items to add. |
AddRange(ReadOnlySpan<T>)
Adds a collection of items to the end of the list.
Declaration
public void AddRange(ReadOnlySpan<T> items)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<T> |
items |
The items to add. |
AsSpan()
Returns a Span<T> view of the list.
Declaration
public Span<T> AsSpan()
Returns
Type | Description |
---|---|
Span<T> |
A Span<T> view of the list. |
Clear()
Empties the list.
Declaration
public void Clear()
Contains(T)
Searches for item
in the list.
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T |
item |
The item to search for. |
Returns
Type | Description |
---|---|
True if the item is in the list, false if it is not. |
CopyTo(T[], int)
Copies the list into an array.
Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
T[] |
array |
The destination array to copy the list into. |
arrayIndex |
The starting index in the destination array. |
Exceptions
Type | Condition |
---|---|
|
|
|
|
There was not enough space in the |
Dispose()
Returns any allocated memory to the pool.
Declaration
public void Dispose()
IndexOf(T)
Searches for item
in the list and returns its index.
Returns -1
if the item
is missing.
Declaration
public int IndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T |
item |
The item to search for. |
Returns
Type | Description |
---|---|
The index of |
Insert(int, T)
Inserts item
into the list at index
.
Declaration
public void Insert(int index, T item)
Parameters
Type | Name | Description |
---|---|---|
index |
The index at which to insert the item. |
|
T |
item |
The item to insert. |
Exceptions
Type | Condition |
---|---|
The index is outside the bounds of the list. |
Pop()
Removes and returns an item from the end of the list.
Declaration
public T Pop()
Returns
Type | Description |
---|---|
T |
The last item in the list. |
Exceptions
Type | Condition |
---|---|
The list is empty. |
Remove(T)
Searches for item
in the list and removes it.
Returns false
if the item
is missing.
Declaration
public bool Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T |
item |
The item to search for. |
Returns
Type | Description |
---|---|
True if the item was removed, false if it was missing. |
RemoveAt(int)
Removes the item at index
.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
index |
The index from which to remove the item. |
Exceptions
Type | Condition |
---|---|
The index is outside the bounds of the list. |