Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_arrayQueue.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
45#ifndef TPL_ARRAYQUEUE_H
46#define TPL_ARRAYQUEUE_H
47
48#include <bit>
49#include <limits>
50#include <ahAssert.H>
51#include <ahDefs.H>
52#include <htlist.H>
53#include <ah-dry.H>
54#include <ah-args-ctor.H>
55#include <tpl_dynDlist.H>
56#include <tpl_memArray.H>
57#include <ah-iterator.H>
58
59namespace Aleph {
60
78template <typename T>
79class ArrayQueue : protected MemArray<T>,
80 public LocateFunctions<ArrayQueue<T>, T>,
81 public FunctionalMethods<ArrayQueue<T>, T>,
82 public GenericKeys<ArrayQueue<T>, T>,
83 public EqualSequenceMethod<ArrayQueue<T>>,
84 public StlAlephIterator<ArrayQueue<T>>
85{
86private:
87 size_t front_index; // items are extracted from this point
88 size_t rear_index; // new item is inserted by this point
89
91 void increase_index(size_t &i, const size_t inc = 1) const noexcept
92 {
93 i += inc;
94 i %= this->dim;
95 }
96
98 T &rear_item(const size_t i = 0) noexcept
99 {
100 const size_t offset = (rear_index + this->dim - (i + 1) % this->dim) % this->dim;
101 return this->access(offset);
102 }
103
106 const T &rear_item(const size_t i = 0) const noexcept
107 {
108 const size_t offset = (rear_index + this->dim - (i + 1) % this->dim) % this->dim;
109 return this->access(offset);
110 }
111
113 void recenter_indices() noexcept
114 {
115 front_index = 0;
116 rear_index = this->dim == 0 ? 0 : this->n % this->dim;
117 }
118
119public:
120 using Item_Type = T;
121 using MemArray<T>::Min_Dim;
122 using MemArray<T>::capacity;
123 using MemArray<T>::size;
124 using MemArray<T>::is_empty;
125 using MemArray<T>::is_valid;
127
129 void swap(ArrayQueue &q) noexcept
130 {
131 this->MemArray<T>::swap(q);
132 std::swap(front_index, q.front_index);
133 std::swap(rear_index, q.rear_index);
134 }
135
141 ArrayQueue(const size_t sz = 8) : MemArray<T>(sz), front_index(0), rear_index(0)
142 {
143 this->disable_annotations(); // circular layout: items are not a prefix
144 }
145
150 requires(std::is_copy_constructible_v<T> and std::is_copy_assignable_v<T>)
151 : MemArray<T>(q.dim), front_index(0), rear_index(0)
152 {
153 this->disable_annotations();
154 for (size_t i = 0; i < q.n; ++i)
155 this->access(i) = q.access((q.front_index + i) % q.dim);
156 this->n = q.n;
157 rear_index = q.n % this->dim;
158 }
159
161 ArrayQueue(ArrayQueue &&q) noexcept
162 : MemArray<T>(std::move(q)), front_index(q.front_index), rear_index(q.rear_index)
163 {
164 q.front_index = 0;
165 q.rear_index = 0;
166 q.disable_annotations(); // the empty source is still a circular queue
167 }
168
170
173 requires(std::is_copy_constructible_v<T> and std::is_copy_assignable_v<T>)
174 {
175 if (this == &q)
176 return *this;
177
178 ArrayQueue copy(q);
179 swap(copy);
180
181 return *this;
182 }
183
185 void empty() noexcept
186 {
188 front_index = 0;
189 rear_index = 0;
190 }
191
193 void clear() noexcept
194 {
195 empty();
196 }
197
203 {
205 front_index = 0;
206 rear_index = 0;
207 }
208
219 void reserve(const size_t cap)
220 {
221 if (cap <= this->dim)
222 return;
223
224 this->reallocate(cap, front_index);
226 }
227
230 {
231 std::swap(front_index, q.front_index);
232 std::swap(rear_index, q.rear_index);
233 static_cast<MemArray<T> *>(this)->swap(q);
234 return *this;
235 }
236
237private:
238 T &complete_put() noexcept
239 {
240 T &ret_val = this->access(rear_index);
242 ++this->n;
243 return ret_val;
244 }
245
247 template <class U>
248 T &put_item(U &&item)
249 {
250 if (this->n == this->dim) // growing frees the buffer that item may live in
251 {
252 T &ret_val = this->grow_and_insert(this->n, std::forward<U>(item), front_index);
254 return ret_val;
255 }
256
257 this->access(rear_index) = std::forward<U>(item);
258 return complete_put();
259 }
260
261public:
270 T &put(const T &item)
271 {
272 return put_item(item);
273 }
274
283 T &put(T &&item)
284 {
285 return put_item(std::move(item));
286 }
287
289 T &append(const T &item)
290 {
291 return put(item);
292 }
293
295 T &append(T &&item)
296 {
297 return put(std::forward<T>(item));
298 }
299
301 T &insert(const T &item)
302 {
303 return put(item);
304 }
305
307 T &insert(T &&item)
308 {
309 return put(std::forward<T>(item));
310 }
311
323 T &putn(const size_t sz)
324 {
325 ah_underflow_error_if(sz == 0 and this->n == 0) << "queue is empty";
326 const size_t cap = this->dim == 0 ? this->Min_Dim : this->dim;
327 const size_t max_sz = cap > std::numeric_limits<size_t>::max() / 2
328 ? std::numeric_limits<size_t>::max() - this->n : 2 * cap - this->n;
329 ah_overflow_error_if(sz > max_sz) << "Maximum putn size reached";
330
331 size_t remaining = sz;
332 while (remaining > 0)
333 {
334 const size_t available = this->dim - this->n;
335 if (available == 0)
336 {
337 if (this->expand(front_index))
339 continue;
340 }
341
342 const size_t delta = remaining < available ? remaining : available;
344 this->n += delta;
345 remaining -= delta;
346 }
347
348 return rear_item();
349 }
350
357 {
358 ah_underflow_error_if(this->n == 0) << "queue is empty";
359
360 T ret_val = std::move(this->access(front_index));
361 --this->n;
363
364 if (this->contract(front_index))
366
367 return ret_val;
368 }
369
376 T &getn(const size_t i)
377 {
378 ah_underflow_error_if(i >= this->n) << "queue is empty";
379
380 this->n -= i;
382
383 if (this->contract(front_index))
385
386 return this->access(front_index);
387 }
388
395 T &front(const size_t i = 0)
396 {
397 ah_range_error_if(i >= this->n) << "index of front out of range";
398
399 return this->access((front_index + i) % this->dim);
400 }
401
404 const T &front(const size_t i = 0) const
405 {
406 ah_range_error_if(i >= this->n) << "index of front out of range";
407
408 return this->access((front_index + i) % this->dim);
409 }
410
417 T &rear(const size_t i = 0)
418 {
419 ah_range_error_if(i >= this->n) << "index of rear out of range";
420
421 return rear_item(i);
422 }
423
426 const T &rear(const size_t i = 0) const
427 {
428 ah_range_error_if(i >= this->n) << "index of rear out of range";
429
430 return rear_item(i);
431 }
432
439 T &operator[](const size_t i)
440 {
441 ah_out_of_range_error_if(i >= this->n) << "queue index out of range";
442 return front(i);
443 }
444
447 const T &operator[](const size_t i) const
448 {
449 ah_out_of_range_error_if(i >= this->n) << "queue index out of range";
450 return front(i);
451 }
452
459 T &operator()(const size_t i) noexcept
460 {
461 assert(i < this->n);
462 return this->access((front_index + i) % this->dim);
463 }
464
467 const T &operator()(const size_t i) const noexcept
468 {
469 assert(i < this->n);
470 return this->access((front_index + i) % this->dim);
471 }
472
478 {
479 ah_underflow_error_if(this->n == 0) << "queue is empty";
480 return front();
481 }
482
485 const T &first() const
486 {
487 ah_underflow_error_if(this->n == 0) << "queue is empty";
488 return front();
489 }
490
496 {
497 ah_underflow_error_if(this->n == 0) << "queue is empty";
498 return rear();
499 }
500
503 const T &last() const
504 {
505 ah_underflow_error_if(this->n == 0) << "queue is empty";
506 return rear();
507 }
508
510 T &get_first() { return first(); }
513 const T &get_first() const { return first(); }
514
516 T &get_last() { return last(); }
519 const T &get_last() const { return last(); }
520
522 T &top() { return first(); }
525 const T &top() const { return first(); }
526
528 T remove_first() { return get(); }
529
531 T pop() { return get(); }
532
534 T &push(const T &item) { return put(item); }
535
537 T &push(T &&item) { return put(std::move(item)); }
538
545 {
546 ah_underflow_error_if(this->n == 0) << "queue is empty";
547 T result = std::move(rear_item());
548 rear_index = (rear_index + this->dim - 1) % this->dim;
549 --this->n;
550 if (this->contract(front_index))
552 return result;
553 }
554
561 {
562 for (size_t i = 0; i < this->n / 2; ++i)
563 std::swap(front(i), rear(i));
564 return *this;
565 }
566
574 template <class Operation>
576 bool traverse(Operation &operation)
578 {
579 if (this->n == 0)
580 return true;
581
582 for (size_t i = 0, idx = front_index; i < this->n; increase_index(idx), ++i)
583 if (not static_cast<bool>(operation(this->access(idx))))
584 return false;
585 return true;
586 }
587
589 template <class Operation>
591 bool traverse(Operation &operation) const
593 {
594 if (this->n == 0)
595 return true;
596
597 for (size_t i = 0, idx = front_index; i < this->n; increase_index(idx), ++i)
598 if (not static_cast<bool>(operation(static_cast<const T &>(this->access(idx)))))
599 return false;
600 return true;
601 }
602
604 template <class Operation>
606 bool traverse(Operation &&operation) const
608 {
609 return traverse<Operation>(operation);
610 }
611
613 template <class Operation>
615 bool traverse(Operation &&operation)
617 {
618 return traverse<Operation>(operation);
619 }
620
627 struct Iterator : public MemArray<T>::Iterator
628 {
629 using Base = typename MemArray<T>::Iterator;
630 using Base::Base;
632
636 : Base(q.ptr, q.dim, q.n, q.front_index,
637 q.n == 0 ? 0 : (q.rear_index + q.dim - 1) % q.dim)
638 {}
639
641 Iterator(const ArrayQueue &) = delete;
642 };
643
646};
647
660template <typename T>
661class FixedQueue : public LocateFunctions<FixedQueue<T>, T>,
662 public FunctionalMethods<FixedQueue<T>, T>,
663 public GenericKeys<FixedQueue<T>, T>,
664 public EqualSequenceMethod<FixedQueue<T>>,
665 public StlAlephIterator<FixedQueue<T>>
666{
667 size_t dim;
669 size_t front_index; /* index of oldest inserted item */
671 size_t mask;
672 size_t num_items;
673
674 void increase_index(size_t &i, const size_t inc = 1) const noexcept
675 {
676 assert(((i + inc) % dim) == ((i + inc) & mask));
677
678 i += inc;
679 i &= mask;
680 }
681
682 T &rear_item(const size_t i = 0) noexcept
683 {
684 assert(static_cast<size_t>((rear_index - i - 1) & mask) == (rear_index - i - 1) % dim);
685
686 return array[static_cast<size_t>((rear_index - i - 1) & mask)];
687 }
688
691 const T &rear_item(const size_t i = 0) const noexcept
692 {
693 assert(static_cast<size_t>((rear_index - i - 1) & mask) == (rear_index - i - 1) % dim);
694
695 return array[static_cast<size_t>((rear_index - i - 1) & mask)];
696 }
697
698public:
699 using Item_Type = T;
700
701 void swap(FixedQueue &q) noexcept
702 {
703 std::swap(dim, q.dim);
704 std::swap(array, q.array);
705 std::swap(front_index, q.front_index);
706 std::swap(rear_index, q.rear_index);
707 std::swap(mask, q.mask);
708 std::swap(num_items, q.num_items);
709 }
710
712 void empty() noexcept
713 {
715 }
716
722 void clear() noexcept
723 {
724 empty();
725 }
726
737 FixedQueue(size_t d = 1024)
738 // Don't change the default value because you would risk of
739 // breaking the tests
740 : dim(0), array(nullptr), front_index(0), rear_index(0), mask(0), num_items(0)
741 {
742 // Without the logarithm of a double: log2(0) is -inf, and past 2^63
743 // the shift 1 << (log2(d) + 1) is of 64 bits or more. bit_ceil() is
744 // computed when the program is compiled for a capacity known then, as
745 // that logarithm was
746 ah_overflow_error_if(d > (std::numeric_limits<size_t>::max() >> 1) + 1)
747 << "FixedQueue: no power of two that a size_t holds is at least " << d;
748 dim = std::bit_ceil(d);
749 // Before new[]: for dim items whose bytes do not fit in a size_t, what
750 // new[] asks of the allocator depends on the compiler
751 ah_overflow_error_if(dim > std::numeric_limits<size_t>::max() / sizeof(T))
752 << "FixedQueue capacity overflow";
753 mask = dim - 1;
754 array = new T[dim];
755 }
756
758 {
759 if (array != nullptr)
760 delete[] array;
761 }
762
772 {
773 try
774 {
775 // num_items slots along the circular index. Comparing with
776 // rear_index copied nothing from a full queue (front_index equals
777 // rear_index then) and ran past the buffer when the queue wraps.
778 for (size_t i = 0, idx = front_index; i < num_items; ++i, increase_index(idx))
779 array[idx] = q.array[idx];
780 }
781 catch (...)
782 {
783 delete[] array; // the destructor does not run when a constructor throws
784 throw;
785 }
786 }
787
796 FixedQueue(FixedQueue &&q) noexcept
797 : dim(0), array(nullptr), front_index(0), rear_index(0), mask(0), num_items(0)
798 {
799 swap(q);
800 }
801
803
806 {
807 if (this == &q)
808 return *this;
809
810 FixedQueue tmp(q);
811 swap(tmp);
812 return *this;
813 }
814
817 {
818 swap(q);
819 return *this;
820 }
821
827 T &put(const T &item) noexcept
828 {
829 assert(num_items < dim);
830 array[rear_index] = item;
831 T &ret_val = array[rear_index];
833 num_items++;
834 return ret_val;
835 }
836
838 T &put(T &&item) noexcept
839 {
840 assert(num_items < dim);
841 array[rear_index] = std::forward<T>(item);
842 T &ret_val = array[rear_index];
844 num_items++;
845 return ret_val;
846 }
847
849 T &append(const T &item) noexcept
850 {
851 return put(item);
852 }
853
855 T &append(T &&item) noexcept
856 {
857 return put(std::forward<T>(item));
858 }
859
861 T &insert(const T &item) noexcept
862 {
863 return put(item);
864 }
865
867 T &insert(T &&item) noexcept
868 {
869 return put(std::forward<T>(item));
870 }
871
877 T &putn(const size_t n) noexcept
878 {
879 assert(num_items + n < dim);
881 num_items += n;
882 return rear_item();
883 }
884
889 T get() noexcept
890 {
891 assert(num_items > 0);
892 num_items--;
893 T ret_val = std::move(array[front_index]);
895 return ret_val;
896 }
897
904 T &getn(const size_t n) noexcept
905 {
906 assert(num_items >= n);
907 num_items -= n;
909 return array[front_index];
910 }
911
917 T &front(const size_t i = 0) noexcept
918 {
919 assert(i < num_items);
920 return array[(front_index + i) & mask];
921 }
922
925 const T &front(const size_t i = 0) const noexcept
926 {
927 assert(i < num_items);
928 return array[(front_index + i) & mask];
929 }
930
936 T &rear(const size_t i = 0) noexcept
937 {
938 assert(i < num_items);
939 return rear_item(i);
940 }
941
944 const T &rear(const size_t i = 0) const noexcept
945 {
946 assert(i < num_items);
947 return rear_item(i);
948 }
949
951 [[nodiscard]] constexpr size_t size() const noexcept
952 {
953 return num_items;
954 }
955
957 [[nodiscard]] constexpr bool is_empty() const noexcept
958 {
959 return num_items == 0;
960 }
961
963 [[nodiscard]] constexpr size_t capacity() const noexcept
964 {
965 return dim;
966 }
967
975 template <class Operation>
977 bool traverse(Operation &operation)
979 {
980 if (num_items == 0)
981 return true;
982 for (size_t i = 0, idx = front_index; i < num_items; increase_index(idx), ++i)
983 if (not static_cast<bool>(operation(array[idx])))
984 return false;
985 return true;
986 }
987
989 template <class Operation>
991 bool traverse(Operation &operation) const
993 {
994 if (num_items == 0)
995 return true;
996
997 for (size_t i = 0, idx = front_index; i < num_items; increase_index(idx), ++i)
998 if (not static_cast<bool>(operation(static_cast<const T &>(array[idx]))))
999 return false;
1000 return true;
1001 }
1002
1004 template <class Operation>
1006 bool traverse(Operation &&operation = Operation()) const
1007 noexcept(Aleph::NothrowPredicateWith<Operation &, const T &>)
1008 {
1009 return traverse<Operation>(operation);
1010 }
1011
1013 template <class Operation>
1015 bool traverse(Operation &&operation = Operation())
1016 noexcept(Aleph::NothrowPredicateWith<Operation &, T &>)
1017 {
1018 return traverse<Operation>(operation);
1019 }
1020
1027 struct Iterator : public MemArray<T>::Iterator
1028 {
1029 using Base = typename MemArray<T>::Iterator;
1030 using Base::Base;
1032
1037 : Base(q.array, q.dim, q.num_items, q.front_index, (q.rear_index - 1) & q.mask)
1038 {}
1039
1041 Iterator(const FixedQueue &) = delete;
1042 };
1043
1046};
1047
1048} // end namespace Aleph
1049
1050#endif /* TPL_ARRAYQUEUE_H */
Variadic constructor macros for containers.
Container traversal and functional operation mixins.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Definition ah-errors.H:727
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
Definition ah-errors.H:517
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Definition ah-errors.H:611
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Definition ah-errors.H:356
STL-compatible iterator adapters for Aleph containers.
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.
Definition ahDry.H:123
Queue implemented with a single dynamic array.
const T & rear(const size_t i=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
T & put(T &&item)
Move an item to the rear of the queue.
T & insert(T &&item)
See put(T && item).
bool traverse(Operation &operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
See traverse(Operation & operation).
T & front(const size_t i=0)
Return the i-th oldest item of the queue.
T & push(T &&item)
Alias for put(); enqueue an item by moving it at the rear.
void empty_and_release()
Empty the queue and reduce storage to Min_Dim.
const T & operator()(const size_t i) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
ArrayQueue(const size_t sz=8)
Construct a queue with capacity sz
T & top()
Alias for first(); throws std::underflow_error if empty.
const T & top() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
T pop()
Alias for get(); remove the oldest item in FIFO order.
const T & first() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
T & rear(const size_t i=0)
Return the i-th youngest item of the queue.
T & put(const T &item)
Copy and put an item in the queue.
T & insert(const T &item)
See put(const T & item).
T & last()
Return the youngest item, in O(1).
T & put_item(U &&item)
Shared body of both put() overloads.
bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
Traverse all the elements from the oldest to the youngest and execute operation on each on them.
const T & last() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
ArrayQueue & operator=(const ArrayQueue &q)
Copy assign (copy and swap: same queue order as the copy constructor)
const T & get_last() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void clear() noexcept
See empty().
T & complete_put() noexcept
void increase_index(size_t &i, const size_t inc=1) const noexcept
Advance a physical index modulo the allocated capacity.
T & first()
Return the oldest item, in O(1).
void empty() noexcept
Empty the queue keeping its capacity; both ends restart at slot 0.
T & get_last()
Alias for last(); throws std::underflow_error if empty.
void recenter_indices() noexcept
Reset indices after relocating the logical sequence to slot zero.
T remove_last()
Remove the youngest item.
ArrayQueue & reverse()
Reverse the logical queue in place.
T & getn(const size_t i)
Remove the i oldest items of the queue.
T remove_first()
Remove the oldest item; same complexity and exceptions as get().
ArrayQueue & operator=(ArrayQueue &&q) noexcept
Move assign.
bool traverse(Operation &&operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
See traverse(Operation & operation).
T & get_first()
Alias for first(); throws std::underflow_error if empty.
const T & front(const size_t i=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
T & operator()(const size_t i) noexcept
Access an item by FIFO position with debug assertions.
ArrayQueue(const ArrayQueue &q)
Copy constructor.
T & append(const T &item)
See put(const T & item).
T & operator[](const size_t i)
Access an item by its FIFO position.
T & putn(const size_t sz)
Add sz logical slots at the rear without initializing scalars.
T & push(const T &item)
Alias for put(); enqueue a copy at the rear.
const T & get_first() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
T get()
Remove the oldest item of the queue and return a copy.
T Item_Type
Type stored in the queue.
const T & operator[](const size_t i) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void reserve(const size_t cap)
Reserve capacity for at least cap items, keeping the queue order.
ArrayQueue(ArrayQueue &&q) noexcept
Move constructor.
T & rear_item(const size_t i=0) noexcept
Access the i-th item counting backwards from the youngest item.
void swap(ArrayQueue &q) noexcept
Swap this with q
const T & rear_item(const size_t i=0) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool traverse(Operation &&operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
See traverse(Operation & operation).
T & append(T &&item)
See put(T && item).
Read-only view of an Aleph iterator: the iterator of a constant container.
Very simple queue implemented with a contiguous array.
T & insert(const T &item) noexcept
See put(const T& item).
T & append(const T &item) noexcept
See put(const T& item).
T & put(const T &item) noexcept
Put an item into the queue by copy.
FixedQueue & operator=(const FixedQueue &q)
Copy assign.
T & insert(T &&item) noexcept
See put(const T& item).
const T & front(const size_t i=0) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool traverse(Operation &&operation=Operation()) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
See traverse(Operation & operation).
const T & rear_item(const size_t i=0) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
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.
T & rear_item(const size_t i=0) noexcept
FixedQueue & operator=(FixedQueue &&q) noexcept
Move assign.
FixedQueue(const FixedQueue &q)
Copy constructor: the copy holds the items of q, in the same slots.
void clear() noexcept
Empties the container.
bool traverse(Operation &operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
See traverse(Operation & operation).
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.
const T & rear(const size_t i=0) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
void swap(FixedQueue &q) noexcept
FixedQueue(size_t d=1024)
Construct a queue of capacity the immediately two power of d
T & front(const size_t i=0) noexcept
Return the i-th oldest item.
T & append(T &&item) noexcept
See put(const T& item).
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.
T & rear(const size_t i=0) noexcept
Return the i-th youngest item.
constexpr size_t size() const noexcept
Return the number of items.
FixedQueue(FixedQueue &&q) noexcept
Move constructor: takes the array and the items of q.
T & put(T &&item) noexcept
See put(const T& item).
bool traverse(Operation &&operation=Operation()) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
See traverse(Operation & operation).
constexpr size_t capacity() const noexcept
Return the queue capacity (maximum number of element to be stored)
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...
size_t size() const noexcept
Return the number of elements.
T & grow_and_insert(const size_t pos, U &&item, const size_t first=0)
Grow a full array and insert one item: relocate_and_insert().
size_t contract_threshold
Number of items at or below which contract() halves the capacity.
void empty_and_release()
Clear the array and reduce allocated storage to Min_Dim.
static constexpr size_t Min_Dim
bool expand(const size_t first=0)
Grow a full array, including an empty moved-from array.
void disable_annotations() noexcept
Make the whole buffer accessible and stop annotating it.
constexpr size_t capacity() const noexcept
The type of element of array.
bool is_valid() const noexcept
bool is_empty() const noexcept
Return true is the array is empty.
void reallocate(const size_t cap, const size_t first=0)
Relocate the logical sequence into a new buffer.
void empty() noexcept
Empties the container.
T & access(const size_t i) noexcept
Return a modifiable reference to the ith element.
void swap(MemArray &a) noexcept
Swap in constant time this with a
Mixin providing equality comparison for sequence containers.
Definition ah-dry.H:2945
Common methods to the Aleph-w ( ) containers.
Definition ah-dry.H:1235
and
Insert a new element into the container by constructing it from the given args.
Definition ah-dry.H:1273
Common sequential searching methods on containers.
Definition ah-dry.H:555
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
PredicateWith<F, Args...>, and neither the call nor the conversion of its result to bool can throw.
f(args...) is a valid call whose result is usable as a condition.
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.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Definition ahAlgo.H:584
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
Simple iterator on elements of a queue.
Iterator(const ArrayQueue &)=delete
A constant queue is iterated through Const_Iterator.
Iterator(ArrayQueue &q)
Iterator on the modifiable queue q, in FIFO order (from the oldest item), including an empty moved-fr...
typename MemArray< T >::Iterator Base
Simple iterator on elements of a queue.
Iterator(FixedQueue &q) noexcept
Iterator on the modifiable queue q, from the oldest item.
typename MemArray< T >::Iterator Base
Iterator(const FixedQueue &)=delete
A constant queue is iterated through Const_Iterator.
Simple iterator on elements of array.
Generic list of items stored in a container.
Definition ah-dry.H:2896
Dynamic doubly linked list implementation.
Simple, scalable, contiguous dynamic array.