Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
slink_nc.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
39# ifndef SLINK_NC_H
40# define SLINK_NC_H
41
42# include <aleph.H>
43# include <ah-errors.H>
44
45namespace Aleph
46{
56 {
57 protected:
59
60 public:
62 Slink_Nc() : next(nullptr) { /* empty */ }
63
65 Slink_Nc(const Slink_Nc &) : next(nullptr) { /* empty */ }
66
67 ~Slink_Nc() { /* empty */ }
68
71 {
72 if (&link == this)
73 return *this;
74
75 ah_invalid_argument_if(not is_empty()) << "link is not empty";
76
77 next = nullptr;
78
79 return *this;
80 }
81
83 void reset()
84 {
85 assert(this not_eq nullptr);
86 next = nullptr;
87 }
88
90 bool is_empty() const
91 {
92 assert(this not_eq nullptr);
93 return next == nullptr;
94 }
95
98 {
99 assert(this not_eq nullptr);
100 return next;
101 }
102
107 const Slink_Nc * get_next() const
108 {
109 assert(this not_eq nullptr);
110 return next;
111 }
112
120 void insert(Slink_Nc * p)
121 {
122 assert(this not_eq nullptr);
123 assert(p not_eq nullptr);
124 assert(p->is_empty());
125 p->next = next;
126 next = p;
127 }
128
138 {
139 assert(this not_eq nullptr);
141 next = ret_val->next;
142 ret_val->reset();
143 return ret_val;
144 }
145
147 {
150
151 public:
152
153 Iterator() : head(nullptr), curr(nullptr) { /* Empty */ }
154
155 Iterator(Slink_Nc * head_ptr) : head(head_ptr), curr(head->get_next())
156 {
157 // empty
158 }
159
161 {
162 // empty
163 }
164
166 : head(head_ptr), curr(curr_ptr)
167 {
168 // empty
169 }
170
172 {
173 assert(curr != nullptr and head != nullptr);
174 curr = head->get_next();
175 }
176
178 {
179 assert(curr != nullptr and head != nullptr);
180 curr = new_curr;
181 }
182
184 {
185 head = new_head;
186 curr = head->get_next();;
187 }
188
189 bool has_curr() const
190 {
191 assert(head != nullptr);
192 return curr != nullptr;
193 }
194
197 {
198 assert(curr != nullptr and head != nullptr);
199 return curr;
200 }
201
203 {
204 ah_overflow_error_if(not has_curr()) << "Not element in list";
205 return get_curr_ne();
206 }
207
209 bool is_in_first() const { return curr == head->next; }
210
213 {
214 curr = curr->get_next();
215 }
216
217 void next()
218 {
219 ah_overflow_error_if(not has_curr()) << "Not next element in list";
220 next_ne();
221 }
222
224 bool operator == (const Iterator & it) const { return curr == it.curr; }
225
227 bool operator != (const Iterator & it) const { return curr != it.curr; }
228
229 bool verify(Slink_Nc * l) const { return head == l; }
230
231 bool verify(const Iterator & it) const { return head == it.head; }
232 };
233
234 };
235}
236
237# endif
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Definition ah-errors.H:463
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Definition ah-errors.H:639
Core header for the Aleph-w library.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
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.
DynList< int > l