FileAccess Orion

FastPriorityQueue
in package
implements Iterator, Countable, Serializable

This is an efficient implementation of an integer priority queue in PHP

This class acts like a queue with insert() and extract(), removing the elements from the queue and it also acts like an Iterator without removing the elements. This behaviour can be used in mixed scenarios with high performance boost.

Interfaces, Classes, Traits and Enums

Iterator
Countable
Serializable

Table of Contents

EXTR_BOTH  = \SplPriorityQueue::EXTR_BOTH
EXTR_DATA  = \SplPriorityQueue::EXTR_DATA
EXTR_PRIORITY  = \SplPriorityQueue::EXTR_PRIORITY
$count  : int
Total number of elements in the queue
$extractFlag  : int
$index  : int
Index of the current element in the queue
$maxPriority  : int|null
Max priority
$priorities  : array<string|int, mixed>
Array of priorities
$subIndex  : int
Sub index of the current element in the same priority level
$subPriorities  : array<string|int, mixed>
Array of priorities used for the iteration
$values  : array<string|int, mixed>
Elements of the queue, divided by priorities
contains()  : bool
Does the queue contain the given datum?
count()  : int
Get the total number of elements in the queue
current()  : mixed
Get the current element in the queue
extract()  : mixed
Extract an element in the queue according to the priority and the order of insertion
hasPriority()  : bool
Does the queue have an item with the given priority?
insert()  : mixed
Insert an element in the queue with a specified priority
isEmpty()  : bool
Check if the queue is empty
key()  : int
Get the index of the current element in the queue
next()  : mixed
Set the iterator pointer to the next element in the queue without removing the previous element
remove()  : bool
Remove an item from the queue
rewind()  : mixed
Rewind the current iterator
serialize()  : string
Serialize
setExtractFlags()  : mixed
Set the extract flag
toArray()  : array<string|int, mixed>
Serialize to an array
unserialize()  : void
Deserialize
valid()  : bool
Check if the current iterator is valid
nextAndRemove()  : mixed
Set the iterator pointer to the next element in the queue removing the previous element

Constants

Properties

$priorities

Array of priorities

protected array<string|int, mixed> $priorities = []

$subIndex

Sub index of the current element in the same priority level

protected int $subIndex = 0

$subPriorities

Array of priorities used for the iteration

protected array<string|int, mixed> $subPriorities = []

$values

Elements of the queue, divided by priorities

protected array<string|int, mixed> $values = []

Methods

contains()

Does the queue contain the given datum?

public contains(mixed $datum) : bool
Parameters
$datum : mixed
Return values
bool

count()

Get the total number of elements in the queue

public count() : int
Return values
int

current()

Get the current element in the queue

public current() : mixed
Return values
mixed

extract()

Extract an element in the queue according to the priority and the order of insertion

public extract() : mixed
Return values
mixed

hasPriority()

Does the queue have an item with the given priority?

public hasPriority(int $priority) : bool
Parameters
$priority : int
Return values
bool

insert()

Insert an element in the queue with a specified priority

public insert(mixed $value, int $priority) : mixed
Parameters
$value : mixed
$priority : int
Return values
mixed

isEmpty()

Check if the queue is empty

public isEmpty() : bool
Return values
bool

key()

Get the index of the current element in the queue

public key() : int
Return values
int

next()

Set the iterator pointer to the next element in the queue without removing the previous element

public next() : mixed
Return values
mixed

remove()

Remove an item from the queue

public remove(mixed $datum) : bool

This is different than ; its purpose is to dequeue an item.

Note: this removes the first item matching the provided item found. If the same item has been added multiple times, it will not remove other instances.

Parameters
$datum : mixed
Return values
bool

False if the item was not found, true otherwise.

rewind()

Rewind the current iterator

public rewind() : mixed
Return values
mixed

setExtractFlags()

Set the extract flag

public setExtractFlags(int $flag) : mixed
Parameters
$flag : int
Return values
mixed

toArray()

Serialize to an array

public toArray() : array<string|int, mixed>

Array will be priority => data pairs

Return values
array<string|int, mixed>

unserialize()

Deserialize

public unserialize(string $data) : void
Parameters
$data : string
Return values
void

valid()

Check if the current iterator is valid

public valid() : bool
Return values
bool

nextAndRemove()

Set the iterator pointer to the next element in the queue removing the previous element

protected nextAndRemove() : mixed
Return values
mixed

Search results