Struct SparseListSlim<T>
- Namespace
- LfrlAnvil
- Assembly
- LfrlAnvil.Core.dll
Represents a slim version of a sparse dynamic array of objects.
public struct SparseListSlim<T>
Type Parameters
T
Element type.
- Inherited Members
- Extension Methods
Properties
Capacity
Gets the number of maximum elements that this list can contain without resizing the underlying buffer.
public int Capacity { get; }
Property Value
Count
Gets the number of elements contained in this list.
public readonly int Count { get; }
Property Value
First
Gets the LinkedListSlimNode<T> that contains the oldest element in this list.
public LinkedListSlimNode<T>? First { get; }
Property Value
IsEmpty
Specifies whether or not this list is empty.
public bool IsEmpty { get; }
Property Value
this[int]
Gets a reference to an element at the given index, or null reference, when element at the given index does not exist.
public ref T this[int index] { get; }
Parameters
index
intThe zero-based index of the element reference to get.
Property Value
- T
Last
Gets the LinkedListSlimNode<T> that contains the newest element in this list.
public LinkedListSlimNode<T>? Last { get; }
Property Value
Sequential
Gets a SparseListSlim<T>.Sequence instance associated with this list, that allows to enumerate over all of its elements in index order.
public SparseListSlim<T>.Sequence Sequential { get; }
Property Value
Methods
Add(T)
Adds item
to the tail of this list.
public int Add(T item)
Parameters
item
TItem to add.
Returns
- int
Zero-based index at which the added
item
exists.
AddDefault(out int)
Adds an element with default value to the tail of this list and returns its reference.
public ref T? AddDefault(out int index)
Parameters
index
intout parameter that returns a zero-based index at which the added element exists.
Returns
- T
Reference to the added element.
Clear()
Removes all elements from this list.
public void Clear()
Contains(int)
Checks whether or not an item at the specified position exists.
[Pure]
public bool Contains(int index)
Parameters
index
intZero-based index to check for item existence.
Returns
- bool
true when item at the specified position exists, otherwise false.
Create(int)
Creates a new empty SparseListSlim<T> instance.
[Pure]
public static SparseListSlim<T> Create(int minCapacity = 0)
Parameters
Returns
- SparseListSlim<T>
New SparseListSlim<T> instance.
GetEnumerator()
Creates a new LinkedListSlimEnumerator<T> instance for this list.
public LinkedListSlimEnumerator<T> GetEnumerator()
Returns
- LinkedListSlimEnumerator<T>
New LinkedListSlimEnumerator<T> instance.
Remarks
This allows to enumerate over SparseListSlim<T> instances in the order of item addition. See Sequential for the ability to enumerate in index order instead.
GetNode(int)
Attempts to get a LinkedListSlimNode<T> that contains an item, that exists at the specified position.
[Pure]
public LinkedListSlimNode<T>? GetNode(int index)
Parameters
index
intZero-based index of an item to get a LinkedListSlimNode<T> for.
Returns
- LinkedListSlimNode<T>?
LinkedListSlimNode<T> instance that contains an item at the specified position, or null, when an item does not exist.
GetRefOrAddDefault(int, out bool)
Gets a reference to an element at the specified position, or adds a new element with default value and returns its reference, if element at the specified position does not exist.
public ref T? GetRefOrAddDefault(int index, out bool exists)
Parameters
index
intThe zero-based index of the element reference to get, or to add a new element at.
exists
boolout parameter, that returns true, when an element already exists at the specified position, otherwise false, when a new element was added.
Returns
- T
Reference to an element at the specified position.
Exceptions
- ArgumentOutOfRangeException
When
index
is less than zero.
Remove(int)
Attempts to remove an item at the specified position from this list.
public bool Remove(int index)
Parameters
index
intThe zero-based index of an element to be removed.
Returns
- bool
true when existing item was removed, otherwise false.
Remove(int, out T)
Attempts to remove an item at the specified position from this list.
public bool Remove(int index, out T removed)
Parameters
index
intThe zero-based index of an element to be removed.
removed
Tout parameter, that returns removed item.
Returns
- bool
true when existing item was removed, otherwise false.
ResetCapacity(int)
Attempts to increase or decrease this list's Capacity, while ensuring that all current elements will fit.
public void ResetCapacity(int minCapacity = 0)
Parameters
TryAdd(int, T)
Attempts to add item
to this list at the specified position.
public bool TryAdd(int index, T item)
Parameters
index
intZero-based index at which to attempt to add the
item
.item
TItem to add.
Returns
- bool
true when
item
was added, otherwise false, when another item already exists at the specified position.
Exceptions
- ArgumentOutOfRangeException
When
index
is less than zero.