Table of Contents

Class LifoBuffer<T>

Namespace
Garyon.DataStructures
Assembly
Garyon.dll

Provides a buffer storing elements in a LIFO (last-in-first-out) order. The buffer cycles through its fixed capacity, automatically overwriting the oldest elements upon appending an element.

public sealed class LifoBuffer<T>

Type Parameters

T

The type of the stored elements.

Inheritance
LifoBuffer<T>
Inherited Members
Extension Methods

Constructors

LifoBuffer(int)

Provides a buffer storing elements in a LIFO (last-in-first-out) order. The buffer cycles through its fixed capacity, automatically overwriting the oldest elements upon appending an element.

public LifoBuffer(int capacity)

Parameters

capacity int

The fixed capacity of the buffer.

Properties

Appends

The number of appends that have been made to the buffer.

public int Appends { get; }

Property Value

int

Capacity

The maximum number of elements that can be stored in the buffer.

public int Capacity { get; }

Property Value

int

Methods

Append(T)

Appends a value to the buffer. If the buffer is full, the oldest element will be automatically overwritten.

public void Append(T value)

Parameters

value T

The value to append to the buffer.

GetBuffer()

Gets the buffer as a ReadOnlySpan<T>. The order of the elements does not indicate the order of the appends.

public ReadOnlySpan<T> GetBuffer()

Returns

ReadOnlySpan<T>

The buffer as a ReadOnlySpan<T>.

GetOrderedBuffer(out ReadOnlySpan<T>, out ReadOnlySpan<T>)

Gets the buffer split into two ReadOnlySpan<T> instances, showing the slice representing the newest and the oldest elements. The buffer is split to preserve its memory contiguity property.

public void GetOrderedBuffer(out ReadOnlySpan<T> newest, out ReadOnlySpan<T> oldest)

Parameters

newest ReadOnlySpan<T>

The ReadOnlySpan<T> representing the newest elements that were appended to the buffer. The last element of this span is the most recent. The span may be empty, indicating that either the buffer is empty, or the last appended item overwrote the last item in the buffer, meaning that the next append will overwrite the first item in the buffer.

oldest ReadOnlySpan<T>

The ReadOnlySpan<T> representing the oldest elements that were appended to the buffer. The first element of this span is the oldest. The span may be empty, indicating that either the buffer is empty. If at least one item has been added to the buffer, this span will never be empty.