Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_dynListQueue.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
32
44# ifndef TPL_DYNLISTQUEUE_H
45# define TPL_DYNLISTQUEUE_H
46
47# include <iostream>
48# include <ahDry.H>
49# include <ahIterator.H>
50# include <ah-args-ctor.H>
51# include <htlist.H>
52# include <tpl_dynDlist.H>
53
54namespace Aleph {
55
62 template <typename T>
64 : public LocateFunctions<DynListQueue<T>, T>,
65 public FunctionalMethods<DynListQueue<T>, T>,
66 public GenericKeys<DynListQueue<T>, T>,
67 public EqualToMethod<DynListQueue<T>>,
68 public StlAlephIterator<DynListQueue<T>>
69{
71 size_t num_items = 0;
72
74
75public:
76
78 void swap(DynListQueue & __q) noexcept
79 {
80 std::swap(num_items, __q.num_items);
81 q.swap(__q.q);
82 }
83
85 DynListQueue() noexcept : num_items(0) { /* empty */ }
86
89 {
90 // empty
91 }
92
95 {
96 swap(__q);
97 }
98
100
103 {
104 if (this == &rhs)
105 return *this;
106
107 q = rhs.q;
108 num_items = rhs.num_items;
109
110 return *this;
111 }
112
115 {
116 std::swap(num_items, rhs.num_items);
117 q.swap(rhs.q);
118 return *this;
119 }
120
122 [[nodiscard]] constexpr size_t size() const noexcept { return num_items; }
123
125 [[nodiscard]] bool is_empty() const noexcept { return q.is_empty(); }
126
128
129 using Item_Type = T;
130
138 T & put(const T & data)
139 {
140 T & ret_val = q.append(data);
141 ++num_items;
142 return ret_val;
143 }
144
152 T & put(T && data)
153 {
154 T & ret_val = q.append(std::forward<T>(data));
155 ++num_items;
156 return ret_val;
157 }
158
159 T & append(const T & data) { return put(data); }
160
161 T & append(T && data)
162 {
163 return put(std::forward<T>(data));
164 }
165
166 T & insert(const T & data) { return put(data); }
167
168 T & insert(T && data)
169 {
170 return put(std::forward<T>(data));
171 }
172
182 template <typename... Args>
184 {
185 return put(T(std::forward<Args>(args)...));
186 }
187
189 T pop() { return get(); }
190
196 void clear() noexcept { empty(); }
197
204 {
206 --num_items;
207 return ret_val;
208 }
209
216 {
217 return q.get_first();
218 }
219
225 const T & front() const
226 {
227 return q.get_first();
228 }
229
235 T & rear()
236 {
237 return q.get_last();
238 }
239
245 const T & rear() const
246 {
247 return q.get_last();
248 }
249
252 {
253 q.empty();
254 num_items = 0;
255 assert(q.is_empty());
256 }
257
265 template <class Operation>
267 {
268 return q.traverse(operation);
269 }
270
272 template <class Operation>
274 {
275 return q.traverse(operation);
276 }
277
279 template <class Operation>
281 {
282 return q.traverse(std::forward<Operation>(operation));
283 }
284
286 template <class Operation>
288 {
289 return q.traverse(std::forward<Operation>(operation));
290 }
291
300 T * search(const T & key) noexcept
301 {
302 return this->find_ptr([&key](const T & item) { return item == key; });
303 }
304
306 const T * search(const T & key) const noexcept
307 {
308 return const_cast<DynListQueue*>(this)->search(key);
309 }
310
312 using Key_Type = T;
313
320 struct Iterator : public DynList<T>::Iterator
321 {
322 using Base = typename DynList<T>::Iterator;
323 using Base::Base;
324
326 };
327};
328
329} // end namespace Aleph
330# endif // TPL_DYNLISTQUEUE_H
331
Variadic constructor macros for containers.
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Definition ahDry.H:113
Iterator traits and STL-compatible iterator wrappers.
Dynamic queue of elements of generic type T based on single linked list.
const T & front() const
Return a const reference to the oldest item in the queue.
DynListQueue & operator=(const DynListQueue &rhs)
Assign to this a copy of rhs
T & put(const T &data)
The type of element.
bool traverse(Operation &&operation=Operation()) const
DynListQueue(DynListQueue &&__q) noexcept
Construct in constant time a queue from __q
T Key_Type
Key_Type is required by EqualToMethod mixin.
constexpr size_t size() const noexcept
Return the number of elements.
T get()
Remove the oldest item of the queue.
const T & rear() const
Return a const reference to the youngest item in the queue.
bool traverse(Operation &operation) const
void swap(DynListQueue &__q) noexcept
Swap this with __q in constant time.
void empty() noexcept
Empty the queue.
T & put(T &&data)
Put an item by moving.
T & front()
Return a modifiable reference to the oldest item in the queue.
const T * search(const T &key) const noexcept
bool traverse(Operation &&operation=Operation())
bool traverse(Operation &operation)
Traverse all the elements from the oldest (front) to the youngest (rear) and execute operation on eac...
void clear() noexcept
Empties the container.
T pop()
Alias for get() - removes and returns the front item.
T & insert(const T &data)
T & append(const T &data)
T & emplace(Args &&... args)
Construct an item in place at the rear of the queue.
DynListQueue() noexcept
Construct an empty queue.
DynListQueue(const DynListQueue &__q)
Construct a copy of __q
T Item_Type
The type of set.
T & rear()
Return a modifiable reference to the youngest item in the queue.
T * search(const T &key) noexcept
Search for an item in the queue using equality comparison.
bool is_empty() const noexcept
Return true if this is empty.
Iterator on the items of list.
Definition htlist.H:1420
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
T & append(const T &item)
Definition htlist.H:1271
T & get_last() const
Return the last item of the list.
Definition htlist.H:1363
T & get_first() const
Return the first item of the list.
Definition htlist.H:1375
void empty() noexcept
empty the list
Definition htlist.H:1389
DynList & swap(DynList &l) noexcept
Definition htlist.H:1176
constexpr bool is_empty() const noexcept
Definition htlist.H:419
Equality test for containers.
Definition ah-dry.H:1826
Common methods to the Aleph-w ( ) containers.
Definition ah-dry.H:642
Common sequential searching methods on containers.
Definition ah-dry.H:196
T * find_ptr(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criterion.
Definition ah-dry.H:349
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
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
Definition ah-zip.H:105
Iterator on elements of a queue.
typename DynList< T >::Iterator Base
Iterator(const DynListQueue< T > &q) noexcept
Generic list of items stored in a container.
Definition ah-dry.H:1714
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
Definition ah-dry.H:97
Dynamic doubly linked list implementation.