45#ifndef TPL_ARRAYQUEUE_H
46#define TPL_ARRAYQUEUE_H
92 return this->
access(offset);
176 if (this->
expand(front_index))
178 this->
access(rear_index) = item;
185 if (this->
expand(front_index))
187 this->
access(rear_index) = std::forward<T>(item);
200 return put(std::forward<T>(item));
212 return put(std::forward<T>(item));
230 const size_t max_sz = 2 * this->
dim - this->
n;
233 size_t remaining = sz;
234 while (remaining > 0)
239 if (this->
expand(front_index))
288 return this->
access(front_index);
301 return this->
access((front_index + i) % this->
dim);
324 template <
class Operation>
337 template <
class Operation>
344 template <
class Operation>
351 template <
class Operation>
421 std::swap(
dim, q.dim);
422 std::swap(
array, q.array);
425 std::swap(
mask, q.mask);
465 if (
array !=
nullptr)
539 return put(std::forward<T>(item));
551 return put(std::forward<T>(item));
641 template <
class Operation>
653 template <
class Operation>
660 template <
class Operation>
667 template <
class Operation>
686 :
Base(q.array, q.dim, q.num_items, q.front_index, (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 & 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.
ArrayQueue & operator=(ArrayQueue &&q) noexcept
Move assign.
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 & putn(const size_t sz)
Put in constant time sz empty entries to the stack.
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 & operator=(FixedQueue &&q) noexcept
Move assign.
FixedQueue(const FixedQueue &q)
Copy constructor.
void clear() noexcept
Empties the container.
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.
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.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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.