Queue

Source: lib/Queue.cs

This page is generated from the source by scripts/gen-reference.py.

Queue, Stack and PriorityQueue<TElement, TPriority>: first in first out, last in first out, and smallest priority first, for unmanaged items, backed by an Arena. Each is a handle whose copies share contents, and default(...) is "not created": it is empty, and adding fails.

var work = Queue<int>.Create(arena);
work.Enqueue(start);
while (work.TryDequeue(out int next)) { ... work.Enqueue(neighbor); ... }

The names are .NET's, with Try in front of the ones that take an item out (Dequeue, Pop, Peek): there are no exceptions to say a collection is empty.

Members

Create

public static Queue<T> Create(Arena arena, int initialCapacity = 16)

Returns a new queue in arena, or a not-created queue if it is out of memory.

IsCreated

public bool IsCreated

Count

public int Count

Enqueue

public bool Enqueue(T item)

Adds an item at the back. Returns false if the queue isn't created or the arena is full.

TryDequeue

public bool TryDequeue(out T item)

Takes the item at the front. Returns false if the queue is empty.

TryPeek

public bool TryPeek(out T item)

The item at the front, without taking it. Returns false if the queue is empty.

Clear

public void Clear()

GetEnumerator

public Enumerator GetEnumerator()

For foreach: the items from front to back. Don't change the queue during the loop.

Clone

public Queue<T> Clone(Arena target)

Returns an independent copy in target, or a not-created queue if this one isn't created or the target is out of memory.

Stack

Create

public static Stack<T> Create(Arena arena, int initialCapacity = 16)

Returns a new stack in arena, or a not-created stack if it is out of memory.

IsCreated

public bool IsCreated

Count

public int Count

Push

public bool Push(T item)

Puts an item on top. Returns false if the stack isn't created or the arena is full.

TryPop

public bool TryPop(out T item)

Takes the item on top. Returns false if the stack is empty.

TryPeek

public bool TryPeek(out T item)

The item on top, without taking it. Returns false if the stack is empty.

Clear

public void Clear()

GetEnumerator

public Enumerator GetEnumerator()

For foreach: the items from the top down, as .NET's Stack. Don't change the stack during the loop.

Clone

public Stack<T> Clone(Arena target)

Returns an independent copy in target, or a not-created stack if this one isn't created or the target is out of memory.

PriorityQueue

Create

public static PriorityQueue<TElement, TPriority> Create(
    Arena arena,
    int initialCapacity = 16)

Returns a new queue in arena, or a not-created queue if it is out of memory.

IsCreated

public bool IsCreated

Count

public int Count

Enqueue

public bool Enqueue(TElement element, TPriority priority)

Adds an element. Returns false if the queue isn't created or the arena is full.

TryDequeue

public bool TryDequeue(out TElement element, out TPriority priority)

Takes the element with the smallest priority. Returns false if the queue is empty.

TryPeek

public bool TryPeek(out TElement element, out TPriority priority)

The element with the smallest priority, without taking it. Returns false if the queue is empty.

Clear

public void Clear()

Clone

public PriorityQueue<TElement, TPriority> Clone(Arena target)

Returns an independent copy in target, or a not-created queue if this one isn't created or the target is out of memory.