PIP 5.5.3
Platform-Independent Primitives
Public Member Functions | List of all members
PIQueue< T > Class Template Reference

A container class inherited from the PIDeque with queue functionality. More...

#include <piqueue.h>

Inheritance diagram for PIQueue< T >:
Inheritance graph
[legend]

Public Member Functions

 PIQueue ()
 Constructs an empty array.
 
PIDeque< T > & enqueue (const T &v)
 Puts an element on the queue.
 
PIDeque< T > & enqueue (T &&v)
 Move an element on the queue.
 
dequeue ()
 Retrieves and returns an element from the queue. More...
 
T & head ()
 Head element of the queue. More...
 
T & tail ()
 Tail element of the queue. More...
 
PIVector< T > toVector () const
 Converts PIQueue to PIVector.
 
PIDeque< T > toDeque () const
 Converts PIQueue to PIDeque.
 
- Public Member Functions inherited from PIDeque< T >
 PIDeque ()
 Constructs an empty array.
 
 PIDeque (const PIDeque< T > &other)
 Copy constructor.
 
 PIDeque (std::initializer_list< T > init_list)
 Contructs array from C++11 initializer list. More...
 
 PIDeque (const T *data, size_t size)
 Contructs array from raw data. This constructor reserve size and copy from data pointer.
 
 PIDeque (size_t pid_size, const T &e=T())
 Contructs array with size size filled elements e.
 
 PIDeque (size_t piv_size, std::function< T(size_t i)> f)
 Contructs array with size size and elements created by function f(size_t i). More...
 
 PIDeque (PIDeque< T > &&other)
 Move constructor.
 
PIDeque< T > & operator= (const PIDeque< T > &other)
 Assign operator.
 
PIDeque< T > & operator= (PIDeque< T > &&other)
 Assign move operator.
 
iterator begin ()
 Iterator to the first element. More...
 
iterator end ()
 Iterator to the element following the last element. More...
 
reverse_iterator rbegin ()
 Returns a reverse iterator to the first element of the reversed array. More...
 
reverse_iterator rend ()
 Returns a reverse iterator to the element. following the last element of the reversed array. More...
 
size_t size () const
 Number of elements in the container. More...
 
ssize_t size_s () const
 Number of elements in the container as signed value. More...
 
size_t length () const
 Same as size(). More...
 
size_t capacity () const
 Number of elements that the container has currently allocated space for. More...
 
bool isEmpty () const
 Checks if the container has no elements. More...
 
bool isNotEmpty () const
 Checks if the container has elements. More...
 
bool any (std::function< bool(const T &e)> test) const
 Tests whether at least one element in the array passes the test implemented by the provided function test. More...
 
bool every (std::function< bool(const T &e)> test) const
 Tests whether all elements in the array passes the test implemented by the provided function test. More...
 
T & operator[] (size_t index)
 Full access to element by index. More...
 
const T & at (size_t index) const
 Read only access to element by index. More...
 
const T & atWhere (std::function< bool(const T &e)> test, ssize_t start=0, const T &def=T()) const
 Returns the first element of the array that passes the test implemented by the provided function test or def if there is no such element. More...
 
const T & lastAtWhere (std::function< bool(const T &e)> test, ssize_t start=-1, const T &def=T()) const
 Returns the last element of the array that passes the test implemented by the provided function test or def if there is no such element. More...
 
T & back ()
 Last element. More...
 
T & front ()
 Last element. More...
 
bool operator== (const PIDeque< T > &v) const
 Compare operator with array v.
 
bool operator!= (const PIDeque< T > &v) const
 Compare operator with array v.
 
bool contains (const T &e, ssize_t start=0) const
 Tests if element e exists in the array. More...
 
bool contains (const PIDeque< T > &v, ssize_t start=0) const
 Tests if all elements of v exists in the array. More...
 
int entries (const T &e, ssize_t start=0) const
 Count elements equal e in the array. More...
 
int entries (std::function< bool(const T &e)> test, ssize_t start=0) const
 Count elements in the array passes the test implemented by the provided function test. More...
 
ssize_t indexOf (const T &e, ssize_t start=0) const
 Returns the first index at which a given element e can be found in the array, or -1 if it is not present. More...
 
ssize_t indexWhere (std::function< bool(const T &e)> test, ssize_t start=0) const
 Returns the first index passes the test implemented by the provided function test, or -1 if it is not present. can be found in the array, or -1 if it is not present. More...
 
ssize_t lastIndexOf (const T &e, ssize_t start=-1) const
 Returns the last index at which a given element e can be found in the array, or -1 if it is not present. More...
 
ssize_t lastIndexWhere (std::function< bool(const T &e)> test, ssize_t start=-1) const
 Returns the last index passes the test implemented by the provided function test, or -1 if it is not present. More...
 
T * data (size_t index=0)
 Pointer to array. More...
 
const T * data (size_t index=0) const
 Read only pointer to array. More...
 
PIDeque< T > getRange (size_t index, size_t count) const
 Creates sub-array of this array. More...
 
template<typename T1 = T, typename std::enable_if<!std::is_trivially_copyable< T1 >::value, int >::type = 0>
PIDeque< T > & clear ()
 Clear array, remove all elements. More...
 
PIDeque< T > & fill (const T &e=T())
 Assigns element 'e' to all items in the array. More...
 
PIDeque< T > & fill (std::function< T(size_t i)> f)
 Assigns result of function 'f(size_t i)' to all items in the array. More...
 
PIDeque< T > & assign (const T &e=T())
 Same as fill(). More...
 
template<typename T1 = T, typename std::enable_if<!std::is_trivially_copyable< T1 >::value, int >::type = 0>
PIDeque< T > & assign (size_t new_size, const T &e)
 First does resize(new_size) then fill(e). More...
 
PIDeque< T > & resize (size_t new_size, const T &e=T())
 Sets size of the array, new elements are copied from e. More...
 
PIDeque< T > & resize (size_t new_size, std::function< T(size_t i)> f)
 Sets size of the array, new elements created by function f(size_t i). More...
 
PIDeque< T > & reserve (size_t new_size)
 Attempts to allocate memory for at least new_size elements. More...
 
PIDeque< T > & insert (size_t index, const T &e=T())
 Inserts value e at index position in the array. More...
 
PIDeque< T > & insert (size_t index, T &&e)
 Inserts value e at index position in the array. More...
 
PIDeque< T > & insert (size_t index, const PIDeque< T > &v)
 Inserts array v at index position in the array. More...
 
PIDeque< T > & insert (size_t index, std::initializer_list< T > init_list)
 Inserts the given elements at index position in the array. More...
 
PIDeque< T > & remove (size_t index, size_t count=1)
 Removes count elements from the middle of the array, starting at index position. More...
 
void swap (PIDeque< T > &other)
 Swaps array v other with this array. More...
 
PIDeque< T > & sort ()
 Sorts the elements in non-descending order. More...
 
PIDeque< T > & sort (std::function< bool(const T &a, const T &b)> comp)
 Sorts the elements in non-descending order. More...
 
PIDeque< T > & reverse ()
 Reverses this array. More...
 
PIDeque< T > reversed () const
 Returns reversed array. More...
 
PIDeque< T > & enlarge (ssize_t add_size, const T &e=T())
 Increases or decreases the size of the array by add_size elements. More...
 
PIDeque< T > & removeOne (const T &e)
 Remove no more than one element equal e. More...
 
PIDeque< T > & removeAll (const T &e)
 Remove all elements equal e. More...
 
PIDeque< T > & removeWhere (std::function< bool(const T &e)> test)
 Remove all elements in the array passes the test implemented by the provided function test. More...
 
PIDeque< T > & push_back (const T &e)
 Appends the given element e to the end of the array. More...
 
PIDeque< T > & push_back (T &&e)
 Appends the given element e to the end of the array. More...
 
PIDeque< T > & push_back (std::initializer_list< T > init_list)
 Appends the given elements to the end of the array. More...
 
PIDeque< T > & push_back (const PIDeque< T > &v)
 Appends the given array v to the end of the array. More...
 
PIDeque< T > & append (const T &e)
 Appends the given element e to the end of the array. More...
 
PIDeque< T > & append (T &&e)
 Appends the given element e to the end of the array. More...
 
PIDeque< T > & append (std::initializer_list< T > init_list)
 Appends the given elements to the end of the array. More...
 
PIDeque< T > & append (const PIDeque< T > &v)
 Appends the given array v to the end of the array. More...
 
PIDeque< T > & operator<< (const T &e)
 Appends the given element e to the end of the array. More...
 
PIDeque< T > & operator<< (T &&e)
 Appends the given element e to the end of the array. More...
 
PIDeque< T > & operator<< (const PIDeque< T > &v)
 Appends the given array v to the end of the array. More...
 
PIDeque< T > & push_front (const T &e)
 Appends the given element e to the begin of the array. More...
 
PIDeque< T > & push_front (T &&e)
 Appends the given element e to the begin of the array. More...
 
PIDeque< T > & push_front (const PIDeque< T > &v)
 Appends the given array v to the begin of the array. More...
 
PIDeque< T > & push_front (std::initializer_list< T > init_list)
 Appends the given elements to the begin of the array. More...
 
PIDeque< T > & prepend (const T &e)
 Appends the given element e to the begin of the array. More...
 
PIDeque< T > & prepend (T &&e)
 Appends the given element e to the begin of the array. More...
 
PIDeque< T > & prepend (const PIDeque< T > &v)
 Appends the given array v to the begin of the array. More...
 
PIDeque< T > & prepend (std::initializer_list< T > init_list)
 Appends the given elements to the begin of the array. More...
 
PIDeque< T > & pop_back ()
 Remove one element from the end of the array. More...
 
PIDeque< T > & pop_front ()
 Remove one element from the begining of the array. More...
 
take_back ()
 Remove one element from the end of the array and return it. More...
 
take_front ()
 Remove one element from the begining of the array and return it. More...
 
template<typename ST >
PIDeque< ST > toType () const
 Returns an array converted to another type. More...
 
PIDeque< T > filter (std::function< bool(const T &e)> test) const
 Returns a new array with all elements that pass the test implemented by the provided function bool test(const T & e). More...
 
PIDeque< T > filterIndexed (std::function< bool(size_t index, const T &e)> test) const
 Same as filter() but with index parameter in test. More...
 
PIDeque< T > filterReverse (std::function< bool(const T &e)> test) const
 Same as filter() but from end to begin (from right to left). More...
 
PIDeque< T > filterReverseIndexed (std::function< bool(size_t index, const T &e)> test) const
 Same as filterReverse() but with index parameter in test. More...
 
void forEach (std::function< void(const T &e)> f) const
 Execute function void f(const T & e) for every element in array. More...
 
PIDeque< T > & forEach (std::function< void(T &e)> f)
 Execute function void f(T & e) for every element in array. More...
 
void forEachIndexed (std::function< void(size_t index, const T &e)> f) const
 Same as forEach() but with index parameter in f. More...
 
PIDeque< T > & forEachIndexed (std::function< void(size_t index, T &e)> f)
 Same as forEachIndexed(), but allows you to change the elements of the array. More...
 
void forEachReverse (std::function< void(const T &e)> f) const
 Same as forEach() but from end to begin (from right to left). More...
 
PIDeque< T > & forEachReverse (std::function< void(T &e)> f)
 Same as forEachReverse(), but allows you to change the elements of the array. More...
 
void forEachReverseIndexed (std::function< void(size_t index, const T &e)> f) const
 Same as forEachIndexed() but from end to begin (from right to left). More...
 
PIDeque< T > & forEachReverseIndexed (std::function< void(size_t index, T &e)> f)
 Same as forEachReverseIndexed(), but allows you to change the elements of the array. More...
 
template<typename ST >
PIDeque< ST > map (std::function< ST(const T &e)> f) const
 Сreates a new array populated with the results of calling a provided function ST f(const T & e) on every element in the calling array. More...
 
template<typename ST >
PIDeque< ST > mapIndexed (std::function< ST(size_t index, const T &e)> f) const
 Same as map() but with index parameter in f. More...
 
template<typename ST >
PIDeque< ST > mapReverse (std::function< ST(const T &e)> f) const
 Same as map() but from end to begin (from right to left). More...
 
template<typename ST >
PIDeque< ST > mapReverseIndexed (std::function< ST(size_t index, const T &e)> f) const
 Same as mapReverse() but with index parameter in f. More...
 
template<typename ST >
ST reduce (std::function< ST(const T &e, const ST &acc)> f, const ST &initial=ST()) const
 Applies the function ST f(const T & e, const ST & acc) to each element of the array (from left to right), returns one value. More...
 
template<typename ST >
ST reduceIndexed (std::function< ST(size_t index, const T &e, const ST &acc)> f, const ST &initial=ST()) const
 Same as reduce() but with index parameter in f. More...
 
template<typename ST >
ST reduceReverse (std::function< ST(const T &e, const ST &acc)> f, const ST &initial=ST()) const
 Same as reduce() but from end to begin (from right to left). More...
 
template<typename ST >
ST reduceReverseIndexed (std::function< ST(size_t index, const T &e, const ST &acc)> f, const ST &initial=ST()) const
 Same as reduceReverse() but with index parameter in f. More...
 
PIDeque< PIDeque< T > > reshape (size_t rows, size_t cols, ReshapeOrder order=ReshapeByRow) const
 Changes the dimension of the array, creates a two-dimensional array from a one-dimensional array. More...
 
template<typename C , typename std::enable_if< std::is_same< T, PIDeque< C > >::value, int >::type = 0>
PIDeque< C > flatten (ReshapeOrder order=ReshapeByRow) const
 Changes the dimension of the array, creates a one-dimensional array from a two-dimensional array. More...
 
template<typename C , typename std::enable_if< std::is_same< T, PIDeque< C > >::value, int >::type = 0>
PIDeque< PIDeque< C > > reshape (size_t rows, size_t cols, ReshapeOrder order=ReshapeByRow) const
 Changes the dimension of the two-dimensional array. More...
 
PIDeque< PIDeque< T > > split (const T &separator) const
 Divides an array into a two-dimensional array using the separator separator. More...
 
PIDeque< PIDeque< T > > splitBySize (size_t sz) const
 Divides an array into a two-dimensional array in chunks of no more than sz. More...
 
PIDeque< T > takeRange (size_t index, size_t count)
 Cut sub-array of this array. More...
 

Detailed Description

template<typename T>
class PIQueue< T >

A container class inherited from the PIDeque with queue functionality.

The container is a array of elements organized according to the FIFO principle (first in, first out). Adds enqueue() and \dequeue() functions to PIDeque.

See also
PIDeque

Member Function Documentation

◆ dequeue()

template<typename T >
T PIQueue< T >::dequeue ( )
inline

Retrieves and returns an element from the queue.

Note
This function assumes that the array isn't empty. Otherwise will be undefined behavior.

◆ head()

template<typename T >
T & PIQueue< T >::head ( )
inline

Head element of the queue.

Note
Returns a reference to the head element of the queue. This function assumes that the array isn't empty. Otherwise will be undefined behavior.

◆ tail()

template<typename T >
T & PIQueue< T >::tail ( )
inline

Tail element of the queue.

Returns a reference to the tail element of the queue. This function assumes that the array isn't empty. Otherwise will be undefined behavior.