|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Very simple queue implemented with a contiguous array. More...
#include <tpl_arrayQueue.H>
Classes | |
| struct | Iterator |
| Simple iterator on elements of a queue. More... | |
Public Types | |
| using | Item_Type = T |
Public Types inherited from StlAlephIterator< FixedQueue< T > > | |
| using | iterator = StlIterator< FixedQueue< T > > |
| using | const_iterator = StlConstIterator< FixedQueue< T > > |
Public Member Functions | |
| void | swap (FixedQueue &q) noexcept |
| void | empty () noexcept |
| empty the queue | |
| void | clear () noexcept |
| Empties the container. | |
| FixedQueue (size_t d=1024) | |
Construct a queue of capacity the immediately two power of d | |
| ~FixedQueue () | |
| FixedQueue (const FixedQueue &q) | |
| Copy constructor. | |
| FixedQueue (FixedQueue &&q) noexcept | |
| Move constructor. | |
| template<template< typename > class List> | |
| FixedQueue (const List< T > &l) | |
| template<class It > | |
| FixedQueue (It b, It e) | |
| FixedQueue (std::initializer_list< T > l) | |
| FixedQueue & | operator= (const FixedQueue &q) |
| Copy assign. | |
| FixedQueue & | operator= (FixedQueue &&q) noexcept |
| Move assign. | |
| T & | put (const T &item) noexcept |
| Put an item into the queue by copy. | |
| T & | put (T &&item) noexcept |
| T & | append (const T &item) noexcept |
| T & | append (T &&item) noexcept |
| T & | insert (const T &item) noexcept |
| T & | insert (T &&item) noexcept |
| T & | putn (const size_t n) noexcept |
Put n cells to the queue in constant time. | |
| T | get () noexcept |
| Remove the oldest item of the queue. | |
| T & | getn (const size_t n) noexcept |
| Remove in constant time the n oldest items of the queue. | |
| T & | front (const size_t i=0) const noexcept |
| Return the i-th oldest item. | |
| T & | rear (const size_t i=0) const noexcept |
| Return the i-th youngest item. | |
| constexpr size_t | size () const noexcept |
| Return the number of items. | |
| constexpr bool | is_empty () const noexcept |
Return true if the queue is empty. | |
| constexpr size_t | capacity () const noexcept |
| Return the queue capacity (maximum number of element to be stored) | |
| template<class Operation > | |
| bool | traverse (Operation &operation) |
Traverse all the elements from the youngest to the oldest and execute operation on each on them. | |
| template<class Operation > | |
| bool | traverse (Operation &operation) const |
| template<class Operation > | |
| bool | traverse (Operation &&operation=Operation()) const |
| template<class Operation > | |
| bool | traverse (Operation &&operation=Operation()) |
Public Member Functions inherited from LocateFunctions< FixedQueue< T >, T > | |
| auto | get_it () const |
| Return a properly initialized iterator positioned at the first item on the container. | |
| auto | get_it (const size_t pos) const |
Return a properly initialized iterator positioned at the pos item on the container. | |
| auto | get_itor () const |
Alias of get_it(). | |
| T & | nth_ne (const size_t n) noexcept |
| Return the n‑th element without bounds checking. | |
| const T & | nth_ne (const size_t n) const noexcept |
Const overload of nth_ne(size_t). | |
| T & | nth (const size_t n) |
| Return the n-th item of the container. | |
| const T & | nth (const size_t n) const |
Const overload of nth(size_t). | |
| T * | find_ptr (Operation &operation) noexcept(operation_is_noexcept< Operation >()) |
| Find a pointer to an item in the container according to a searching criterion. | |
| const T * | find_ptr (Operation &operation) const noexcept(operation_is_noexcept< Operation >()) |
Const overload of find_ptr(Operation&). | |
| const T * | find_ptr (Operation &&operation) const noexcept(operation_is_noexcept< Operation >()) |
| Overload of find_ptr() const that accepts rvalues. | |
| T * | find_ptr (Operation &&operation) noexcept(operation_is_noexcept< Operation >()) |
| Overload of find_ptr() that accepts rvalues. | |
| size_t | find_index (Operation &operation) const noexcept(operation_is_noexcept< Operation >()) |
| Find the position of an item in the container according to a searching criterion. | |
| size_t | find_index (Operation &&operation) const noexcept(operation_is_noexcept< Operation >()) |
| Overload of find_index() that accepts rvalues. | |
| std::tuple< bool, T > | find_item (Operation &operation) noexcept(operation_is_noexcept< Operation >()) |
| Safe sequential searching of an item matching a criterion. | |
| std::tuple< bool, T > | find_item (Operation &operation) const noexcept(operation_is_noexcept< Operation >()) |
| std::tuple< bool, T > | find_item (Operation &&operation) noexcept(operation_is_noexcept< Operation >()) |
| Overload of find_item() that accepts rvalues. | |
| std::tuple< bool, T > | find_item (Operation &&operation) const noexcept(operation_is_noexcept< Operation >()) |
| Overload of find_item() const that accepts rvalues. | |
| bool | contains_if (Operation &&operation) const noexcept(operation_is_noexcept< Operation >()) |
| Test if an item satisfying a criterion is present in the container. | |
| bool | contains (const T &item) const |
| Test if an item is present in the container using equality. | |
Public Member Functions inherited from FunctionalMethods< FixedQueue< T >, T > | |
| void | emplace (Args &&... args) |
| Appends a new element into the container by constructing it in-place with the given args. | |
| void | emplace_end (Args &&... args) |
| void | emplace_ins (Args &&... args) |
| Insert a new element into the container by constructing it in-place with the given args. | |
| size_t | ninsert (Args ... args) |
| Insert n variadic items. | |
| size_t | nappend (Args ... args) |
| Append n variadic items. | |
| void | for_each (Operation &operation) |
| Traverse all the container and performs an operation on each element. | |
| void | for_each (Operation &operation) const |
Const overload of for_each(Operation&). | |
| void | for_each (Operation &&operation) const |
| Overload of for_each() const that accepts rvalues. | |
| void | for_each (Operation &&operation) |
| Overload of for_each() that accepts rvalues. | |
| void | each (Operation &operation) |
Alias of for_each(Operation&). | |
| void | each (Operation &operation) const |
Const alias of for_each(Operation&). | |
| void | each (Operation &&operation) const |
| Const alias of each() that accepts rvalues. | |
| void | each (Operation &&operation) |
| Alias of each() that accepts rvalues. | |
| void | each (size_t pos, const size_t slice, Operation &operation) const |
Traverse the container starting at pos taking one item every slice, performing a mutable operation on each visited element. | |
| void | each (const size_t pos, const size_t slice, Operation &&operation) const |
| void | mutable_for_each (Operation &operation) |
| Apply a mutable operation to each element of the container. | |
| void | mutable_for_each (Operation &&operation) |
| bool | all (Operation &operation) const |
| Check if all the elements of the container satisfy a condition. | |
| bool | all (Operation &&operation) const |
| Overload of all() that accepts rvalues. | |
| bool | exists (Operation &op) const |
| Test for existence in the container of an element satisfying a criterion. | |
| bool | exists (Operation &&op) const |
| Overload of exists() that accepts rvalues. | |
| Aleph::DynList< __T > | maps (Operation &op) const |
| Map the elements of the container. | |
| Aleph::DynList< __T > | maps (Operation &&op) const |
| Overload of maps() that accepts rvalues. | |
| Aleph::DynList< __T > | maps_if (Prop prop, Operation &op) const |
| Conditional mapping of the elements of the container. | |
| Aleph::DynList< __T > | maps_if (Prop prop, Operation &&op) const |
| Overload of maps_if() that accepts rvalues. | |
| Aleph::DynList< T > | to_dynlist () const |
| Convert container to DynList. | |
| std::vector< T > | to_vector () const |
| Convert container to std::vector. | |
| __T | foldl (const __T &init, Op &op) const |
| Fold the elements of the container to a specific result. | |
| __T | foldl (const __T &init, Op &&op=Op()) const |
| Overload of foldl() that accepts rvalues. | |
| __T | fold_left (const __T &init, Op &op) const |
| Alias for foldl with the same accumulator type. | |
| __T | fold_left (const __T &init, Op &&op=Op()) const |
| Overload of fold_left() that accepts rvalues. | |
| T | fold (const T &init, Operation &operation) const |
| Simplified version of foldl() where the folded type is the same type of elements stored in the container. | |
| T | fold (const T &init, Operation &&operation) const |
| Overload of fold() that accepts rvalues. | |
| Aleph::DynList< T > | filter (Operation &operation) const |
| Filter the elements of a container according to a matching criterion. | |
| Aleph::DynList< T > | filter (Operation &&operation) const |
| Overload of filter() that accepts rvalues. | |
| Aleph::DynList< const T * > | ptr_filter (Operation &operation) const |
| Filter the elements of a container according to a matching criterion and return a pointer to the matched items in the container. | |
| Aleph::DynList< const T * > | ptr_filter (Operation &&operation) const |
| Overload of ptr_filter() that accepts rvalues. | |
| Aleph::DynList< std::tuple< T, size_t > > | pfilter (Operation &operation) const |
| Filter the elements of a container according to a matching criterion and determine its positions respect to the traversal of container. | |
| Aleph::DynList< std::tuple< T, size_t > > | pfilter (Operation &&operation) const |
| Overload of pfilter() that accepts rvalues. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | partition (Operation &op) const |
| Exclusive partition of container according to a filter criterion. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | partition (Operation &&op) const |
| Overload of partition() that accepts rvalues. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | partition (size_t n) const |
| Exclusive partition of container in the nth item. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | split_half () const |
| Split the container into two halves by alternating elements. | |
| std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > | tpartition (Operation &op) const |
| Exclusive partition of container according to a filter criterion. | |
| std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > | tpartition (Operation &&op) const |
| Overload of tpartition() that accepts rvalues. | |
| size_t | length () const noexcept |
| Count the number of elements of a container. | |
| Aleph::DynList< T > | rev () const |
| Return a list with the elements of container in reverse order respect to its traversal order. | |
| Aleph::DynList< T > | take (const size_t n) const |
| Return a list with the first n elements seen in the container during its traversal. | |
| Aleph::DynList< T > | take (size_t i, const size_t j, const size_t step=1) const |
| Return a list with elements seen in the container between i and j position respect to its traversal. | |
| Aleph::DynList< T > | drop (const size_t n) const |
| Drop the first n elements seen in the container during its traversal. | |
| void | mutable_drop (const size_t n) |
| Drop the first n elements seen from container. | |
Public Member Functions inherited from GenericItems< Container, T > | |
| Aleph::DynList< T > | items () const |
| Return a list of all the elements of a container sorted by traversal order. | |
| Aleph::DynList< T > | keys () const |
Public Member Functions inherited from EqualToMethod< FixedQueue< T > > | |
| bool | equal_to (const FixedQueue< T > &r) const noexcept |
Test if elements of this are exactly contained in another container. | |
| bool | operator== (const FixedQueue< T > &r) const noexcept |
| bool | operator!= (const FixedQueue< T > &r) const noexcept |
| Negation of equal_to() | |
Public Member Functions inherited from StlAlephIterator< FixedQueue< T > > | |
| iterator | begin () noexcept |
| Return an STL-compatible iterator to the first element. | |
| const_iterator | begin () const noexcept |
| Return a const iterator to the first element. | |
| iterator | end () noexcept |
| Return an STL-compatible end iterator. | |
| const_iterator | end () const noexcept |
| Return a const end iterator. | |
| const_iterator | cbegin () const noexcept |
| Return a const iterator to the first element. | |
| const_iterator | cend () const noexcept |
| Return a const end iterator. | |
Private Member Functions | |
| void | increase_index (size_t &i, const size_t inc=1) const noexcept |
| T & | rear_item (const size_t i=0) const noexcept |
Private Attributes | |
| size_t | dim |
| T * | array |
| size_t | front_index |
| size_t | rear_index |
| size_t | mask |
| size_t | num_items |
Additional Inherited Members | |
Related Symbols inherited from FunctionalMethods< FixedQueue< T >, T > | |
| each | |
| each | |
| each | |
Very simple queue implemented with a contiguous array.
The capacity is given in construction time, but this is adjusted to the next two power immediately greater.
This queue is the fastest of Aleph-w ( \(\aleph_\omega\)), but take in account that no bound_statics cheks are performed. You must be sure that you usage is correct.
Definition at line 388 of file tpl_arrayQueue.H.
Definition at line 417 of file tpl_arrayQueue.H.
|
inline |
Construct a queue of capacity the immediately two power of d
The resulting capacity will be the first number such \(2^k \geq d\),
| [in] | d | minimum capacity |
Definition at line 452 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::FixedQueue< T >::dim, Aleph::is_power_of_2(), k, log2(), and Aleph::FixedQueue< T >::mask.
|
inline |
Definition at line 463 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array.
|
inline |
Copy constructor.
Definition at line 470 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::FixedQueue< T >::front_index, and Aleph::FixedQueue< T >::rear_index.
|
inlinenoexcept |
Move constructor.
Definition at line 479 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::swap().
|
inline |
Definition at line 484 of file tpl_arrayQueue.H.
Definition at line 484 of file tpl_arrayQueue.H.
|
inline |
Definition at line 484 of file tpl_arrayQueue.H.
Definition at line 531 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::put().
Definition at line 537 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::put().
|
inlineconstexprnoexcept |
Return the queue capacity (maximum number of element to be stored)
Definition at line 629 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::dim.
Referenced by TEST().
|
inlinenoexcept |
Empties the container.
| none |
Definition at line 440 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::empty().
|
inlinenoexcept |
empty the queue
Definition at line 430 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::front_index, Aleph::FixedQueue< T >::num_items, and Aleph::FixedQueue< T >::rear_index.
Referenced by Aleph::FixedQueue< T >::clear().
Return the i-th oldest item.
| [in] | i | access position respect to oldest item |
Definition at line 599 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::divide_and_conquer_partition_dp(), Aleph::FixedQueue< T >::front_index, and Aleph::FixedQueue< T >::num_items.
Referenced by TEST().
|
inlinenoexcept |
Remove the oldest item of the queue.
Definition at line 571 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::divide_and_conquer_partition_dp(), Aleph::FixedQueue< T >::front_index, Aleph::FixedQueue< T >::increase_index(), and Aleph::FixedQueue< T >::num_items.
Referenced by main(), TEST(), TEST(), TEST(), and WorkersSet< WorkerFct >::worker_handler().
Remove in constant time the n oldest items of the queue.
| [in] | n | number of items to remove |
n entries Definition at line 586 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::divide_and_conquer_partition_dp(), Aleph::FixedQueue< T >::front_index, Aleph::FixedQueue< T >::increase_index(), and Aleph::FixedQueue< T >::num_items.
|
inlineprivatenoexcept |
Definition at line 401 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::dim, Aleph::divide_and_conquer_partition_dp(), and Aleph::FixedQueue< T >::mask.
Referenced by Aleph::FixedQueue< T >::get(), Aleph::FixedQueue< T >::getn(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::putn(), and Aleph::FixedQueue< T >::traverse().
Definition at line 543 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::put().
Definition at line 549 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::put().
|
inlineconstexprnoexcept |
Return true if the queue is empty.
Definition at line 623 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::num_items.
Referenced by main(), TEST(), TEST(), TEST(), TEST(), TEST(), and WorkersSet< WorkerFct >::worker_handler().
|
inline |
Copy assign.
Definition at line 487 of file tpl_arrayQueue.H.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::FixedQueue< T >::swap().
|
inlinenoexcept |
Move assign.
Definition at line 498 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::swap().
Put an item into the queue by copy.
| [in] | item | to put |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 509 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::FixedQueue< T >::dim, Aleph::divide_and_conquer_partition_dp(), Aleph::FixedQueue< T >::increase_index(), Aleph::FixedQueue< T >::num_items, and Aleph::FixedQueue< T >::rear_index.
Referenced by Aleph::FixedQueue< T >::append(), Aleph::FixedQueue< T >::append(), Aleph::FixedQueue< T >::insert(), Aleph::FixedQueue< T >::insert(), WorkersSet< WorkerFct >::schedule_call(), TEST(), TEST(), TEST(), and TEST().
Definition at line 520 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::FixedQueue< T >::dim, Aleph::divide_and_conquer_partition_dp(), Aleph::FixedQueue< T >::increase_index(), Aleph::FixedQueue< T >::num_items, and Aleph::FixedQueue< T >::rear_index.
Put n cells to the queue in constant time.
| [in] | n | number of cells |
Definition at line 559 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::dim, Aleph::divide_and_conquer_partition_dp(), Aleph::FixedQueue< T >::increase_index(), Aleph::FixedQueue< T >::num_items, Aleph::FixedQueue< T >::rear_index, and Aleph::FixedQueue< T >::rear_item().
Referenced by main().
Return the i-th youngest item.
| [in] | i | access position respect to youngest item |
Definition at line 610 of file tpl_arrayQueue.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::FixedQueue< T >::num_items, and Aleph::FixedQueue< T >::rear_item().
|
inlineprivatenoexcept |
Definition at line 409 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::FixedQueue< T >::dim, Aleph::divide_and_conquer_partition_dp(), Aleph::FixedQueue< T >::mask, and Aleph::FixedQueue< T >::rear_index.
Referenced by Aleph::FixedQueue< T >::putn(), and Aleph::FixedQueue< T >::rear().
|
inlineconstexprnoexcept |
Return the number of items.
Definition at line 617 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::num_items.
|
inlinenoexcept |
Definition at line 419 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::FixedQueue< T >::dim, Aleph::FixedQueue< T >::front_index, Aleph::FixedQueue< T >::mask, Aleph::FixedQueue< T >::num_items, and Aleph::FixedQueue< T >::rear_index.
Referenced by Aleph::FixedQueue< T >::FixedQueue(), Aleph::FixedQueue< T >::operator=(), Aleph::FixedQueue< T >::operator=(), and TEST().
|
inline |
Definition at line 668 of file tpl_arrayQueue.H.
References Aleph::divide_and_conquer_partition_dp().
|
inline |
Definition at line 661 of file tpl_arrayQueue.H.
References Aleph::divide_and_conquer_partition_dp().
|
inline |
Traverse all the elements from the youngest to the oldest and execute operation on each on them.
| [in] | operation | to be performed on each element |
true if operation was executed on all elements; false otherwise.This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 642 of file tpl_arrayQueue.H.
References Aleph::FixedQueue< T >::array, Aleph::divide_and_conquer_partition_dp(), Aleph::FixedQueue< T >::front_index, Aleph::FixedQueue< T >::increase_index(), and Aleph::FixedQueue< T >::num_items.
Referenced by TEST(), and Aleph::FixedQueue< T >::traverse().
|
inline |
Definition at line 654 of file tpl_arrayQueue.H.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::FixedQueue< T >::traverse().
|
private |
Definition at line 395 of file tpl_arrayQueue.H.
Referenced by Aleph::FixedQueue< T >::FixedQueue(), Aleph::FixedQueue< T >::FixedQueue(), Aleph::FixedQueue< T >::~FixedQueue(), Aleph::FixedQueue< T >::front(), Aleph::FixedQueue< T >::get(), Aleph::FixedQueue< T >::getn(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::rear_item(), Aleph::FixedQueue< T >::swap(), and Aleph::FixedQueue< T >::traverse().
|
private |
Definition at line 394 of file tpl_arrayQueue.H.
Referenced by Aleph::FixedQueue< T >::FixedQueue(), Aleph::FixedQueue< T >::capacity(), Aleph::FixedQueue< T >::increase_index(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::putn(), Aleph::FixedQueue< T >::rear_item(), and Aleph::FixedQueue< T >::swap().
|
private |
Definition at line 396 of file tpl_arrayQueue.H.
Referenced by Aleph::FixedQueue< T >::FixedQueue(), Aleph::FixedQueue< T >::empty(), Aleph::FixedQueue< T >::front(), Aleph::FixedQueue< T >::get(), Aleph::FixedQueue< T >::getn(), Aleph::FixedQueue< T >::swap(), and Aleph::FixedQueue< T >::traverse().
|
private |
Definition at line 398 of file tpl_arrayQueue.H.
Referenced by Aleph::FixedQueue< T >::FixedQueue(), Aleph::FixedQueue< T >::increase_index(), Aleph::FixedQueue< T >::rear_item(), and Aleph::FixedQueue< T >::swap().
|
private |
Definition at line 399 of file tpl_arrayQueue.H.
Referenced by Aleph::FixedQueue< T >::empty(), Aleph::FixedQueue< T >::front(), Aleph::FixedQueue< T >::get(), Aleph::FixedQueue< T >::getn(), Aleph::FixedQueue< T >::is_empty(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::putn(), Aleph::FixedQueue< T >::rear(), Aleph::FixedQueue< T >::size(), Aleph::FixedQueue< T >::swap(), and Aleph::FixedQueue< T >::traverse().
|
private |
Definition at line 397 of file tpl_arrayQueue.H.
Referenced by Aleph::FixedQueue< T >::FixedQueue(), Aleph::FixedQueue< T >::empty(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::put(), Aleph::FixedQueue< T >::putn(), Aleph::FixedQueue< T >::rear_item(), and Aleph::FixedQueue< T >::swap().