SPHPlayground API
SPHPlayground
sphplayground sphplayground

Datastructures: Queue

A queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence. [1]

The operations of a queue make it a first-in-first-out (FIFO) data structure. [1]

Queue datastructures in SPHPlayground:

Synopsis
interface Queue
Adds a new item to the end of the queue
public enqueue(mixed $value):static
Dequeues a node from the queue
public dequeue():mixed
Observes the first item of the queue without removing it
public peek():mixed
Determine if the queue is empty or not
public isEmpty():bool

Description of queue methods:

Priority Queue data structures

In a priority queue, each element has an associated priority, which determines its order of service. Priority queue serves highest priority items first. [2]

A priority queue is stable if extractions of items with equal priority value occur in the order in which they were inserted. Both Implementations of priority queues here are stable.

The IterablePriorityQueue is a simple implementation of the PriorityQueue interface. It uses PHP arrays as its inner data structure.

Synopsis
interface PriorityQueue implements Queue
Adds a new item to the end of the queue
public enqueue(mixed $value, int $priority = 0):static
Dequeues a node from the queue
public dequeue():mixed
Observes the first item of the queue without removing it
public peek():mixed
Determine if the queue is empty or not
public isEmpty():bool

The StablePriorityQueue class uses SplPriorityQueue as its inner queue but solves the stability problem of the SplPriorityQueue class. Thus The StablePriorityQueue is also stable.

Synopsis
Clones the object
public __clone()
Dequeues a node from the queue
public dequeue():mixed
Inserts value with the priority in the queue
public enqueue(mixed $value, int|float $priority = 0):static
Determine if the queue is empty or not
public isEmpty():bool
Observes the first item of the queue without removing it
public peek():mixed
public count():int
Serializes to an array
public toArray():array

Execution sequence

ExecutionSequence is a prioritized queue of callables that can be executed in the order of their priorities.