Table of Contents

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

int

Count

Gets the number of elements contained in this list.

public readonly int Count { get; }

Property Value

int

First

Gets the LinkedListSlimNode<T> that contains the first element in this list.

public LinkedListSlimNode<T>? First { get; }

Property Value

LinkedListSlimNode<T>?

IsEmpty

Specifies whether or not this list is empty.

public bool IsEmpty { get; }

Property Value

bool

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 int

The 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

LinkedListSlimNode<T>?

Methods

AddAfter(int, T)

Adds item directly after a node identified by the provided index.

public int AddAfter(int index, T item)

Parameters

index int

Identifier of the node after which to add the new item.

item T

Item to add.

Returns

int

Index of the node that holds added item or -1, when provided index 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 int

Identifier of the node before which to add the new item.

item T

Item to add.

Returns

int

Index of the node that holds added item or -1, when provided index does not point to a valid node.

AddFirst(T)

Adds item to the start of this list.

public int AddFirst(T item)

Parameters

item T

Item 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 T

Item 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 int

Zero-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

minCapacity int

Minimum initial Capacity of the created list. Equal to 0 by default.

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 int

Zero-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 int

Index 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 int

Index of a node to remove.

removed T

out 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

bool

true when list is not empty and First node was removed, otherwise false.

RemoveFirst(out T)

Removes the First node from this list.

public bool RemoveFirst(out T removed)

Parameters

removed T

out parameter, that returns removed item.

Returns

bool

true when list is not empty and First node was removed, otherwise false.

RemoveLast()

Removes the Last node from this list.

public bool RemoveLast()

Returns

bool

true when list is not empty and Last node was removed, otherwise false.

RemoveLast(out T)

Removes the Last node from this list.

public bool RemoveLast(out T removed)

Parameters

removed T

out parameter, that returns removed item.

Returns

bool

true when list is not empty and Last node 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

minCapacity int

Minimum desired Capacity of this list. Equal to 0 by default.