Struct LinkedListSlim<T>
- Namespace
- LfrlAnvil
- Assembly
- LfrlAnvil.Core.dll
Represents a slim version of a linked list of objects.
public struct LinkedListSlim<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 first 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 last element in this list.
public LinkedListSlimNode<T>? Last { get; }
Property Value
Methods
AddAfter(int, T)
Adds item
directly after a node identified by the provided index
.
public int AddAfter(int index, T item)
Parameters
index
intIdentifier of the node after which to add the new
item
.item
TItem to add.
Returns
- int
Index of the node that holds added
item
or -1, when providedindex
does not point to a valid node.
AddBefore(int, T)
Adds item
directly before a node identified by the provided index
.
public int AddBefore(int index, T item)
Parameters
index
intIdentifier of the node before which to add the new
item
.item
TItem to add.
Returns
- int
Index of the node that holds added
item
or -1, when providedindex
does not point to a valid node.
AddFirst(T)
Adds item
to the start of this list.
public int AddFirst(T item)
Parameters
item
TItem to add.
Returns
- int
Index of the node that holds added
item
.
AddLast(T)
Adds item
to the end of this list.
public int AddLast(T item)
Parameters
item
TItem to add.
Returns
- int
Index of the node that holds added
item
.
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 LinkedListSlim<T> instance.
[Pure]
public static LinkedListSlim<T> Create(int minCapacity = 0)
Parameters
Returns
- LinkedListSlim<T>
New LinkedListSlim<T> instance.
GetEnumerator()
Creates a new LinkedListSlimEnumerator<T> instance for this list.
public LinkedListSlimEnumerator<T> GetEnumerator()
Returns
- LinkedListSlimEnumerator<T>
New LinkedListSlimEnumerator<T> instance.
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.
Remove(int)
Removes a node identified by the provided index
from this list.
public bool Remove(int index)
Parameters
index
intIndex of a node to remove.
Returns
- bool
true when node was removed successfully, otherwise false.
Remove(int, out T)
Removes a node identified by the provided index
from this list.
public bool Remove(int index, out T removed)
Parameters
index
intIndex of a node to remove.
removed
Tout parameter, that returns removed item.
Returns
- bool
true when node was removed successfully, otherwise false.
RemoveFirst()
Removes the First node from this list.
public bool RemoveFirst()
Returns
RemoveFirst(out T)
Removes the First node from this list.
public bool RemoveFirst(out T removed)
Parameters
removed
Tout parameter, that returns removed item.
Returns
RemoveLast()
Removes the Last node from this list.
public bool RemoveLast()
Returns
RemoveLast(out T)
Removes the Last node from this list.
public bool RemoveLast(out T removed)
Parameters
removed
Tout parameter, that returns removed item.
Returns
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)