\Phabstractic\Data\TypesPriorityQueue

Priority Queue Class - Implements a Priority Queue

This is a list that automatically sorts itself according to Priority objects (data attached to priority numbers)

The lower the number, the higher urgency the item has in the list.

This object relies on AbstractSortedList and provides the sort algorithm required

NOTE: Because it checks against a priority interface, it's possible to have different 'kinds' of priority objects in this list despite its restrictions.

CHANGELOG

1.0: Created PriorityQueue - May 27th, 2013 1.1: Added Falcraft\Data\Types\Range support - October 7th, 2013 2.0: Refactored and re-formatted for inclusion in primus - April 11th, 2015 3.0: reformatted for inclusion in phabstractic - July 24th, 2016 3.0.1: implements configurationinterface - July 31st, 2016

Summary

Methods
Properties
Constants
configure()
saveSettings()
getSettings()
processSettings()
__construct()
top()
topReference()
index()
indexReference()
pop()
popReference()
getList()
peek()
peekReference()
bottom()
bottomReference()
indexRange()
indexRangeReference()
delete()
deletePriority()
pull()
pullReference()
roll()
push()
pushReference()
exchange()
duplicate()
retrievePriority()
__debugInfo()
No public properties found
EQUAL
HIGHER
LOWER
cmp()
$conf
N/A
No private methods found
No private properties found
N/A

Constants

EQUAL

EQUAL

Return Data Equal To Given Urgency Index?

HIGHER

HIGHER

Return Data Equal or Higher To Given Urgency Index?

LOWER

LOWER

Return Data Equal or Lower to Given Urgency Index?

Properties

$conf

$conf : \Phabstractic\Features\Zend\Config\Config

The objects configuration object

Should be an instance of Zend/Config

Type

\Phabstractic\Features\Zend\Config\Config — The object configuration info

Methods

configure()

configure(array|string|\Phabstractic\Features\Zend\Config\Config  $configuration, string  $format = null, mixed  $context = null) : boolean

Configure An Object

Expects an array for configuration however, you can also pass it a filepath where it will read the information from a file automatically detecting the format using the file extension. You can also pass a Zend/Config object already made.

You can also pass a format specifier (forced format) for use in a if $configuration is a string formatted with such information. E.G. to load from a string in the format ini:

$this->configure($configString, 'ini');

The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.

NOTE: You can override/extend the classes used for reading formats by identifying an additional array in the property $this->configReaders. This will merge with the standard formats array.

Parameters

array|string|\Phabstractic\Features\Zend\Config\Config $configuration

The objects configuration information.

string $format

The forced format, or format for configuration string

mixed $context

Any additional information for a reader constructor, such as needed for the YAML format.

Returns

boolean —

True if instantiated

saveSettings()

saveSettings(string  $file, \Phabstractic\Features\Zend\Config\Writer\WriterInterface  $writer = null, boolean  $exclusive = true, mixed  $context = null) 

Save an Object's Configuration to a File

Takes an objects $conf property and writes the information contained therein to a file with a format automatically specified by the filename.

It is possible to retrieve a string of a particular format from this method by specifying the filename '#string' with an extension indicating the desired format, such as '#string.json'.

The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.

NOTE: You can override/extend the classes used for writing formats by identifying an additional array in the property $this->configWriters. This will merge with the standard formats array.

Parameters

string $file

The file path to write to, or '#string.ext'

\Phabstractic\Features\Zend\Config\Writer\WriterInterface $writer

The optional writer object supplied to use (such as a MySQL writer)

boolean $exclusive

Argument provided to toFile(), file exclusive lock when writing

mixed $context

Any additionla writer constructor information (YAML)

getSettings()

getSettings(string  $format,   $context = null) : string|boolean

Retrieve an Object's Configuration Information As String

This is a shortcut to ::saveSettings() which specifies a format and forces the return of a string, using the #string.ext filename -see documentation for ::saveSettings()-

Parameters

string $format

The format to return, must be supported by ::saveSettings(), use $this->configWriters to support additional formats.

$context

Returns

string|boolean —

The formatted string, or false otherwise

processSettings()

processSettings(\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface  $processor) 

Process an Object's Configuration

This uses a Zend\Config\Processor implementation to process the configuration information, such as constants. The processor must be supplied and implement ProcessorInterface

NOTE: Edits the $conf object in place.

Parameters

\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface $processor

The given processor object

__construct()

__construct(mixed  $data = null, \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\FilterInterface  $restrictions = null, mixed  $options = array()) 

The Priority Queue constructor

Accepts data, and the obligatory options parameter

Passes the required restrictions onto the parent class along with the options

This instantiates the class and sets the index

Options: strict - Do we raise appropriate exceptions when values are misaligned?

Parameters

mixed $data

The data to initialize the queue

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\FilterInterface $restrictions

The type restrictions

mixed $options

The options to pass into the object

top()

top() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the top value, (that being the most urgent)

Does not pop the value off the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangeException

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

Data from the priority object, null otherwise

topReference()

topReference() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the top value as a reference (that being the most urgent)

Does not pop the value off the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangeException

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

Data from the priority object, null otherwise

index()

index(integer  $i, string  $order = self::EQUAL) : array|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the data objects specified by the order request as an array

Because this doesn't set references, the code had to be duplicated

Parameters

integer $i

the given urgency level

string $order

the given order, higher, lower, equal

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangeException

if strict and index doesn't exist

Returns

array|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

The array of data items that are equal, higher, or lower than the given urgency index

indexReference()

indexReference(integer  $i, string  $order = self::EQUAL) : array|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the urgency index data items as an array of references

This turns out an array of the data objects that are higher, lower, or equal to the urgency level given.

Parameters

integer $i

the given urgency level

string $order

the given order, higher, lower, equal

Throws

\Phabstractic\Data\Types\Phabstractic\Types\Exception\RangeException

if strict is set and no index

Returns

array|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

An array of references to the data objects

pop()

pop() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Pop the most urgent item off the list

This truncates the list from the top, and returns its value

NOTE: This returns the priority's DATA

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

The data associated with the highest urgency, null otherwise

popReference()

popReference() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Pop the most urgent item off the list as a reference

This truncates the list from the top, and returns its value as a reference

NOTE: This returns the priority's DATA

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

The data associated with the highest urgency, null otherwise

getList()

getList() : array

Retrieve the list element of the list

Returns

array —

The current internal list member

peek()

peek() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Wrapper function for top()

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

Data from priority object, null if otherwise

peekReference()

peekReference() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Wrapper function for topReference()

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

Data from priority object as a reference, null if otherwise

bottom()

bottom() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the least urgent item from the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangeException

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

The data from the priority object, null if otherwise

bottomReference()

bottomReference() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the least urgent item from the list as a reference

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangeException

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

The data from the priority object as a reference, null if otherwise

indexRange()

indexRange(\Phabstractic\Data\Types\Phabstractic\Data\Types\Range  $r) : array

Get A Range Of Indexes

This gets an array of objects that have priorities between ranges

NOTE: The utility function must be used because of incompatibility of array_unique algorithm

Parameters

\Phabstractic\Data\Types\Phabstractic\Data\Types\Range $r

The range to include

Returns

array —

The appropriate array

indexRangeReference()

indexRangeReference(\Phabstractic\Data\Types\Phabstractic\Data\Types\Range  $r) : array

Get A Range Of Index References

This gets an array of objects that have priorities between ranges

NOTE: The utility function must be used because of incompatibility of array_unique algorithm

Parameters

\Phabstractic\Data\Types\Phabstractic\Data\Types\Range $r

The range to include

Returns

array —

The appropriate array

delete()

delete(mixed  $data) : boolean

Deletes an element given by data from the list

This does not need sorting because the list will already be sorted by urgency, eliminating one item does not upset that sort

Parameters

mixed $data

The given data item to remove from the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\TypesException\RangeException

if set to strict and element doesn't exist

Returns

boolean —

Whether the data item was deleted, returns false if data item not in queue

deletePriority()

deletePriority(integer  $priority) : boolean

Delete all elements meeting a particular priority

Pretty straight forward

Parameters

integer $priority

Priority to delete

Returns

boolean —

Successful?

pull()

pull() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Pull the least urgent item off the list

This truncates the lsit from the bottom, and return it's value

NOTE: This returns the priority's DATA

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

The data associated with the lowest urgency, null otherwise

pullReference()

pullReference() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Pull the least urgent item off the list as a reference

This truncates the lsit from the bottom, and return it's value

NOTE: This returns the priority's DATA

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

The data reference associated with the lowest urgency, null otherwise

roll()

roll(  $i) 

Cannot roll a priority queue

Parameters

$i

Throws

\Phabstractic\Data\Types\Exception\RuntimeException

push()

push() : integer|null

Push a value on to the list

This automatically sorts the list after all other requirements have been met

Remember AbstractSortedList is the parent of this abstract class

Returns

integer|null —

Count of new list, null if restrictions not met

pushReference()

pushReference(  $a) : integer|null

Push a reference on to the list (fifo, lifo, etc)

This automatically sorts the list after all other requiresments have been met

Parameters

$a

Returns

integer|null —

Count of new list, null if restrictions are not met

exchange()

exchange() 

Exchange the two top elements of the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RuntimeException

duplicate()

duplicate() 

Duplicate the value at the top of the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RuntimeException

retrievePriority()

retrievePriority(mixed  $data) 

Retrieve reference to priority associated with data

Parameters

mixed $data

The data to search for

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

cmp()

cmp(\Phabstractic\Data\Types\Phabstractic\Data\Type\Resource\PriorityInterface  $l, \Phabstractic\Data\Types\Phabstractic\Data\Type\Resource\PriorityInterface  $r) : integer

Compare Two Priority Objects

This is used by AbstractSortedList to sort the elements of the list

Parameters

\Phabstractic\Data\Types\Phabstractic\Data\Type\Resource\PriorityInterface $l

The first value to compare

\Phabstractic\Data\Types\Phabstractic\Data\Type\Resource\PriorityInterface $r

The second value to compare

Throws

\Phabstractic\Data\Types\Exception\InvalidArgumentException

if the values to compare are not of PriorityInterface

Returns

integer —

The required comparison results.