Skip to content

PgFixedDeque<T>

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Borrows a fixed circular buffer, element count and head index as a double-ended queue.

public readonly ref struct PgFixedDeque<T> where T : unmanaged

Type parameters:

T

An unmanaged element stored directly in the buffer.

The caller owns and synchronizes all three storage locations. Zero-initialized storage is empty. Views alias their buffers; copying an owning inline-array struct copies the queue.

Borrows existing queue storage without changing its contents.

public PgFixedDeque(Span<T> buffer, ref int count, ref int head)

Parameters:

buffer — Span<T>

The complete circular element buffer.

count — int

The number of initialized elements.

head — int

The first element’s physical index, or zero for zero-capacity storage.

Gets the fixed number of elements the queue can hold.

public int Capacity { get; }

Value: int

Gets the count, rejecting an uninitialized view or invalid count or head metadata.

public int Count { get; }

Value: int

Gets whether the queue is empty.

public bool IsEmpty { get; }

Value: bool

Gets whether the queue has no unused capacity.

public bool IsFull { get; }

Value: bool

Gets or replaces an element in logical front-to-back order.

public T this[int index] { get; set; }

Parameters:

index — int

The zero-based logical index.

Value: T

Clears initialized slots and resets the count and head to zero.

public void Clear()

Copies the queue in front-to-back order to nonoverlapping storage.

public void CopyTo(Span<T> destination)

Parameters:

destination — Span<T>

Storage with room for at least Count elements.

A short destination or any overlap with the queue buffer is rejected before copying.

Copies all elements into an owned array, then empties the queue.

public T[] Drain()

Returns: T[]

The removed elements in front-to-back order.

Enumerates elements in front-to-back order without allocating or rearranging the buffer.

public PgFixedDequeEnumerator<T> GetEnumerator()

Returns: PgFixedDequeEnumerator<T>

An enumerator invalidated by structural changes to the queue.

Borrows the queue’s one or two contiguous segments in front-to-back order.

public void GetSpans(out Span<T> first, out Span<T> second)

Parameters:

first — Span<T>

The segment starting at the head.

second — Span<T>

The wrapped segment starting at buffer index zero, possibly empty.

Removes and returns the back element, throwing when empty.

public T PopBack()

Returns: T

The removed element.

Removes and returns the front element, throwing when empty.

public T PopFront()

Returns: T

The removed element.

Appends an element at the back, throwing when full.

public void PushBack(T value)

Parameters:

value — T

The element to append.

Prepends an element at the front, throwing when full.

public void PushFront(T value)

Parameters:

value — T

The element to prepend.

Copies the queue into an independently owned array in front-to-back order.

public T[] ToArray()

Returns: T[]

The queue’s elements.

Removes the back element if present, clearing its former slot.

public bool TryPopBack(out T value)

Parameters:

value — T

The removed element, or default when empty.

Returns: bool

Whether an element was removed.

Removes the front element if present, clearing its former slot.

public bool TryPopFront(out T value)

Parameters:

value — T

The removed element, or default when empty.

Returns: bool

Whether an element was removed.

Appends an element at the back if capacity remains.

public bool TryPushBack(T value)

Parameters:

value — T

The element to append.

Returns: bool

False without changes when full.

Prepends an element at the front if capacity remains.

public bool TryPushFront(T value)

Parameters:

value — T

The element to prepend.

Returns: bool

False without changes when full.