46#ifndef TPL_ARRAYQUEUE_H
47#define TPL_ARRAYQUEUE_H
94 return this->
access(offset);
185 if (this->
expand(front_index))
187 this->
access(rear_index) = item;
194 if (this->
expand(front_index))
196 this->
access(rear_index) = std::forward<T>(item);
230 size_t remaining = sz;
231 while (remaining > 0)
236 if (this->
expand(front_index))
285 return this->
access(front_index);
298 return this->
access((front_index + i) % this->
dim);
321 template <
class Operation>
334 template <
class Operation>
341 template <
class Operation>
348 template <
class Operation>
384 template <
typename T>
422 std::swap(
dim, q.dim);
423 std::swap(
array, q.array);
426 std::swap(
mask, q.mask);
456 if (
array !=
nullptr)
525 T &
append(
T && item)
noexcept {
return put(std::forward<T>(item)); }
531 T &
insert(
T && item)
noexcept {
return put(std::forward<T>(item)); }
611 template <
class Operation>
623 template <
class Operation>
630 template <
class Operation>
637 template <
class Operation>
656 :
Base(q.array, q.dim, q.num_items, q.front_index,
657 (q.rear_index - 1) % q.dim) {}
Variadic constructor macros for containers.
Container traversal and functional operation mixins.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Debug assertion and warning utilities.
Core definitions, constants, and utility macros for Aleph-w.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Queue implemented with a single dynamic array.
ArrayQueue(const size_t sz=8)
Construct a queue with capacity sz
bool traverse(Operation &&operation) const
T & putn(size_t sz)
Put in constant time sz empty entries to the stack.
T & insert(const T &item)
bool traverse(Operation &operation) const
T & complete_put() noexcept
T & front(const size_t i=0) const
Return the i-th oldest item of the queue.
void increase_index(size_t &i, const size_t inc=1) const noexcept
void recenter_indices() noexcept
bool traverse(Operation &operation)
Traverse all the elements from the youngest to the oldest and execute operation on each on them.
T & getn(const size_t i)
Remove the i oldest items of the queue.
ArrayQueue(const ArrayQueue &q)
Copy constructor.
bool traverse(Operation &&operation)
T & append(const T &item)
ArrayQueue & operator=(const ArrayQueue &q)
Copy assign.
T & put(const T &item)
Copy and put an item in the queue.
T & rear(const size_t i=0) const
Return the i-th youngest item of the queue.
T get()
Remove the oldest item of the queue and return a copy.
ArrayQueue(ArrayQueue &&q) noexcept
Move constructor.
void swap(ArrayQueue &q) noexcept
Swap this with q
T & rear_item(const size_t i=0) const noexcept
Very simple queue implemented with a contiguous array.
T & insert(const T &item) noexcept
T & append(const T &item) noexcept
T & put(const T &item) noexcept
Put an item into the queue by copy.
bool traverse(Operation &&operation=Operation())
FixedQueue & operator=(const FixedQueue &q)
Copy assign.
T & insert(T &&item) noexcept
bool traverse(Operation &operation)
Traverse all the elements from the youngest to the oldest and execute operation on each on them.
constexpr bool is_empty() const noexcept
Return true if the queue is empty.
FixedQueue(const FixedQueue &q)
Copy constructor.
T get() noexcept
Remove the oldest item of the queue.
T & putn(const size_t n) noexcept
Put n cells to the queue in constant time.
void swap(FixedQueue &q) noexcept
FixedQueue(size_t d=1024)
Construct a queue of capacity the immediately two power of d
bool traverse(Operation &&operation=Operation()) const
T & append(T &&item) noexcept
void empty() noexcept
empty the queue
void increase_index(size_t &i, const size_t inc=1) const noexcept
T & getn(const size_t n) noexcept
Remove in constant time the n oldest items of the queue.
constexpr size_t size() const noexcept
Return the number of items.
T & rear_item(const size_t i=0) const noexcept
FixedQueue(FixedQueue &&q) noexcept
Move constructor.
T & put(T &&item) noexcept
T & rear(const size_t i=0) const noexcept
Return the i-th youngest item.
constexpr size_t capacity() const noexcept
Return the queue capacity (maximum number of element to be stored)
bool traverse(Operation &operation) const
T & front(const size_t i=0) const noexcept
Return the i-th oldest item.
Simple, scalable and fast dynamic array.
bool contract(const size_t first=0)
Test if n is lesser than contract_threshold and eventually contract the array half long and copies it...
T & access(const size_t i) const noexcept
Return a modifiable reference to the ith element.
bool expand(const size_t first=0)
Test is array is full and if affrimative, then expand the array twice as long and copy the content by...
void swap(MemArray &a) noexcept
Swap in constant time this with a
Equality test for containers.
Common methods to the Aleph-w ( ) containers.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Common sequential searching methods on containers.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_log2_function > > log2(const __gmp_expr< T, U > &expr)
Singly linked list implementations with head-tail access.
const long double offset[]
Offset values indexed by symbol string length (bounded by MAX_OFFSET_INDEX)
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
bool is_power_of_2(unsigned long x)
Taken from http://stackoverflow.com/questions/3638431/determine-if-an-int-is-a-power-of-2-or-not-in-a...
Simple iterator on elements of a queue.
typename MemArray< T >::Iterator Base
Iterator(const ArrayQueue &q)
Simple iterator on elements of a queue.
Iterator(const FixedQueue &q) noexcept
typename MemArray< T >::Iterator Base
Simple iterator on elements of array.
Generic list of items stored in a container.
Dynamic doubly linked list implementation.
Simple, scalable, contiguous dynamic array.