Struct QueueSlim<T>
- Namespace
- LfrlAnvil
- Assembly
- LfrlAnvil.Core.dll
Represents a slim version of first-in, first-out collection of objects implemented as a circular buffer.
public struct QueueSlim<T>Type Parameters
- T
- Element type. 
- Inherited Members
- Extension Methods
Properties
Capacity
Gets the number of maximum elements that this queue can contain without resizing the underlying buffer.
public int Capacity { get; }Property Value
Count
Gets the number of elements contained in this queue.
public int Count { get; }Property Value
IsEmpty
Specifies whether or not this queue is empty.
public bool IsEmpty { get; }Property Value
this[int]
Gets a reference to an element at the given index.
public ref T this[int index] { get; }Parameters
- indexint
- The zero-based index of the element reference to get. 
Property Value
- T
Exceptions
- ArgumentOutOfRangeException
- When - indexis out of bounds.
Methods
AsMemory()
Creates a new QueueSlimMemory<T> instance that represents a view of this queue.
[Pure]
public QueueSlimMemory<T> AsMemory()Returns
- QueueSlimMemory<T>
- New QueueSlimMemory<T> instance. 
Clear()
Removes all elements from this queue.
public void Clear()Create(int)
Creates a new empty QueueSlim<T> instance.
[Pure]
public static QueueSlim<T> Create(int minCapacity = 0)Parameters
Returns
- QueueSlim<T>
- New QueueSlim<T> instance. 
Dequeue()
Attempts to remove the first item from this queue.
public bool Dequeue()Returns
- bool
- true when queue was not empty and first item was removed, otherwise false. 
DequeueRange(int)
Attempts to remove a range of items from the start of this queue.
public int DequeueRange(int count)Parameters
- countint
- Number of elements to remove. 
Returns
- int
- Actual number of removed elements. 
Remarks
Does nothing, when count is less than or equal to 0.
When count is greater than queue's Count,
then clears the queue and returns its old Count.
Enqueue(T)
Adds item to the tail of this queue.
public void Enqueue(T item)Parameters
- itemT
- Item to add. 
EnqueueRange(ReadOnlySpan<T>)
Adds a range of items to the tail of this queue.
public void EnqueueRange(ReadOnlySpan<T> items)Parameters
- itemsReadOnlySpan<T>
- Items to add. 
Remarks
Does nothing when items are empty.
First()
Returns a reference to the first element.
[Pure]
public ref T First()Returns
- T
- Reference to the first element. 
Remarks
May return an invalid reference, when this queue is empty.
GetEnumerator()
Creates a new QueueSlimMemory<T>.Enumerator instance for this queue.
[Pure]
public QueueSlimMemory<T>.Enumerator GetEnumerator()Returns
- QueueSlimMemory<T>.Enumerator
- New QueueSlimMemory<T>.Enumerator instance. 
Last()
Returns a reference to the last element.
[Pure]
public ref T Last()Returns
- T
- Reference to the last element. 
Remarks
May return an invalid reference, when this queue is empty.
ResetCapacity(int)
Attempts to increase or decrease this queue's Capacity, while ensuring that all current elements will fit.
public void ResetCapacity(int minCapacity = 0)Parameters
TryDequeue(out T)
Attempts to remove and return the first item from this queue.
public bool TryDequeue(out T item)Parameters
- itemT
- out parameter that returns the removed first item. 
Returns
- bool
- true when queue was not empty and first item was removed, otherwise false.