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
81 void reset()
82 {
83 assert(this not_eq nullptr);
84 next = nullptr;
85 }
86
88 bool is_empty() const
89 {
90 assert(this not_eq nullptr);
91 return next == nullptr;
92 }
93
96 {
97 assert(this not_eq nullptr);
98 return next;
99 }
100
108 void insert(Slink_Nc * p)
109 {
110 assert(this not_eq nullptr);
111 assert(p not_eq nullptr);
112 assert(p->is_empty());
113 p->next = next;
114 next = p;
115 }
116
126 {
127 assert(this not_eq nullptr);
129 next = ret_val->next;
130 ret_val->reset();
131 return ret_val;
132 }
133
135 {
138
139 public:
140
141 Iterator() : head(nullptr), curr(nullptr) { /* Empty */ }
142
143 Iterator(Slink_Nc * head_ptr) : head(head_ptr), curr(head->get_next())
144 {
145 // empty
146 }
147
149 {
150 // empty
151 }
152
154 : head(head_ptr), curr(curr_ptr)
155 {
156 // empty
157 }
158
160 {
161 assert(curr != nullptr and head != nullptr);
162 curr = head->get_next();
163 }
164
166 {
167 assert(curr != nullptr and head != nullptr);
168 curr = new_curr;
169 }
170
172 {
173 head = new_head;
174 curr = head->get_next();;
175 }
176
177 bool has_curr() const
178 {
179 assert(head != nullptr);
180 return curr != nullptr;
181 }
182
185 {
186 assert(curr != nullptr and head != nullptr);
187 return curr;
188 }
189
191 {
192 ah_overflow_error_if(not has_curr()) << "Not element in list";
193 return get_curr_ne();
194 }
195
197 bool is_in_first() const { return curr == head->next; }
198
201 {
202 curr = curr->get_next();
203 }
204
205 void next() throw(std::exception, std::overflow_error)
206 {
207 ah_overflow_error_if(not has_curr()) << "Not next element in list";
208 next_ne();
209 }
210
212 bool operator == (const Iterator & it) const { return curr == it.curr; }
213
215 bool operator != (const Iterator & it) const { return curr != it.curr; }
216
217 bool verify(Slink_Nc * l) const { return head == l; }
218
219 bool verify(const Iterator & it) const { return head == it.head; }
220 };
221
222 };
223}
224
225# endif
226
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.
void reset() noexcept
Definition htlist.H:516
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
DynList< T > maps(const C &c, Op op)
Classic map operation.
STL namespace.
DynList< int > l