Debian Codegraph @

src/common/elist.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2004,2006 Dizzy
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #ifndef INCLUDED_ELIST_TYPEScxx . . $ `src/common/elist.h:19:9`!
19 #define INCLUDED_ELIST_TYPEScxx . . $ `src/common/elist.h:19:9`!
20
21 namespace pvpgncxx . . $ pvpgn/
22 {
23
24 template<typename T>
25 class elist_nodecxx . . $ pvpgn/elist_node#
26 {
27 public:
28 elist_nodecxx . . $ pvpgn/elist_node#`elist_node<T>`(49f6e7a06ebc5aa8).() : info_cxx . . $ pvpgn/elist_node#info_.(0), prev_cxx . . $ pvpgn/elist_node#prev_.(this), next_cxx . . $ pvpgn/elist_node#next_.(this) {}
29 ~cxx . . $ pvpgn/elist_node#`~elist_node<T>`(ced63f7c635d850d).elist_node() throw() {
30 removecxx . . $ pvpgn/elist_node#remove(49f6e7a06ebc5aa8).();
31 }
32
33 void link_frontcxx . . $ pvpgn/elist_node#link_front(fb184ab358b518a8).(elist_node& where, T& info) {
34 info_cxx . . $ pvpgn/elist_node#info_. = &info;
35 where.next_cxx . . $ pvpgn/elist_node#next_.->prev_cxx . . $ pvpgn/elist_node#prev_. = this;
36 next_cxx . . $ pvpgn/elist_node#next_. = where.next_cxx . . $ pvpgn/elist_node#next_.;
37 prev_cxx . . $ pvpgn/elist_node#prev_. = &where;
38 where.next_cxx . . $ pvpgn/elist_node#next_. = this;
39 }
40
41 void link_backcxx . . $ pvpgn/elist_node#link_back(fb184ab358b518a8).(elist_node& where, T& info) {
42 info_cxx . . $ pvpgn/elist_node#info_. = &info;
43 where.prev_cxx . . $ pvpgn/elist_node#prev_.->next_cxx . . $ pvpgn/elist_node#next_. = this;
44 next_cxx . . $ pvpgn/elist_node#next_. = &where;
45 prev_cxx . . $ pvpgn/elist_node#prev_. = where.prev_cxx . . $ pvpgn/elist_node#prev_.;
46 where.prev_cxx . . $ pvpgn/elist_node#prev_. = this;
47 }
48
49 void removecxx . . $ pvpgn/elist_node#remove(49f6e7a06ebc5aa8).() {
50 /* remove ourselves from any link */
51 prev_cxx . . $ pvpgn/elist_node#prev_.->next_cxx . . $ pvpgn/elist_node#next_. = next_cxx . . $ pvpgn/elist_node#next_.;
52 next_cxx . . $ pvpgn/elist_node#next_.->prev_cxx . . $ pvpgn/elist_node#prev_. = prev_cxx . . $ pvpgn/elist_node#prev_.;
53 prev_cxx . . $ pvpgn/elist_node#prev_. = next_cxx . . $ pvpgn/elist_node#next_. = this;
54 /* poison this to find out bugs a lot earlier */
55 info_cxx . . $ pvpgn/elist_node#info_. = 0;
56 }
57
58 T& infocxx . . $ pvpgn/elist_node#info(c93303b41ac66b6d).() const { return *info_cxx . . $ pvpgn/elist_node#info_.; }
59
60 elist_node* nextcxx . . $ pvpgn/elist_node#next(2c7f7dc3e90659c9).() const { return next_cxx . . $ pvpgn/elist_node#next_.; }
61 elist_node* prevcxx . . $ pvpgn/elist_node#prev(2c7f7dc3e90659c9).() const { return prev_cxx . . $ pvpgn/elist_node#prev_.; }
62
63 private:
64 T* info_cxx . . $ pvpgn/elist_node#info_.;
65 elist_node *prev_cxx . . $ pvpgn/elist_node#prev_., *next_cxx . . $ pvpgn/elist_node#next_.;
66
67 elist_nodecxx . . $ pvpgn/elist_node#`elist_node<T>`(739f07c56bd0e22f).(const elist_node&);
68 elist_node& operatorcxx . . $ pvpgn/elist_node#`operator=`(d8def2c7e2f2fec7).=(const elist_node&);
69 };
70
71 template<typename T>
72 class elistcxx . . $ pvpgn/elist#
73 {
74 public:
75 class iteratorcxx . . $ pvpgn/elist#iterator#
76 {
77 public:
78 iteratorcxx . . $ pvpgn/elist#iterator#iterator(49f6e7a06ebc5aa8).() : ptrcxx . . $ pvpgn/elist#iterator#ptr.(0) {}
79 iteratorcxx . . $ pvpgn/elist#iterator#iterator(3435eda981ce516c).(const iteratorcxx . . $ pvpgn/elist#iterator#& orig) :ptrcxx . . $ pvpgn/elist#iterator#ptr.(orig.ptrcxx . . $ pvpgn/elist#iterator#ptr.) {}
80 ~cxx . . $ pvpgn/elist#iterator#`~iterator`(ced63f7c635d850d).iteratorcxx . . $ pvpgn/elist#iterator#() throw() {}
81
82 iteratorcxx . . $ pvpgn/elist#iterator#& operatorcxx . . $ pvpgn/elist#iterator#`operator=`(e98a2a51dc339f25).=(const iteratorcxx . . $ pvpgn/elist#iterator#& i) {
83 ptrcxx . . $ pvpgn/elist#iterator#ptr. = i.ptrcxx . . $ pvpgn/elist#iterator#ptr.;
84 return *this;
85 }
86
87 bool operatorcxx . . $ pvpgn/elist#iterator#`operator==`(296d7d1a0f763a4).==(const iteratorcxx . . $ pvpgn/elist#iterator#& op) const {
88 return ptrcxx . . $ pvpgn/elist#iterator#ptr. == op.ptrcxx . . $ pvpgn/elist#iterator#ptr.;
89 }
90 bool operatorcxx . . $ pvpgn/elist#iterator#`operator!=`(296d7d1a0f763a4).!=(const iteratorcxx . . $ pvpgn/elist#iterator#& op) const {
91 return ptrcxx . . $ pvpgn/elist#iterator#ptr. != op.ptrcxx . . $ pvpgn/elist#iterator#ptr.;
92 }
93
94 iteratorcxx . . $ pvpgn/elist#iterator#& operatorcxx . . $ pvpgn/elist#iterator#operator++(6c041a7bc1227c87).++() {
95 ptrcxx . . $ pvpgn/elist#iterator#ptr. = ptrcxx . . $ pvpgn/elist#iterator#ptr.->nextcxx . . $ pvpgn/elist_node#next(2c7f7dc3e90659c9).();
96 return *this;
97 }
98 iteratorcxx . . $ pvpgn/elist#iterator# operatorcxx . . $ pvpgn/elist#iterator#operator++(2f2b118cc112d034).++(int) {
99 elist_nodecxx . . $ pvpgn/elist_node#<T>* save = ptrcxx . . $ pvpgn/elist#iterator#ptr.;
100 ptrcxx . . $ pvpgn/elist#iterator#ptr. = ptrcxx . . $ pvpgn/elist#iterator#ptr.->nextcxx . . $ pvpgn/elist_node#next(2c7f7dc3e90659c9).();
101 return iteratorcxx . . $ pvpgn/elist#iterator#(save);
102 }
103
104 T& operatorcxx . . $ pvpgn/elist#iterator#`operator*`(c93303b41ac66b6d).*() const {
105 return ptrcxx . . $ pvpgn/elist#iterator#ptr.->infocxx . . $ pvpgn/elist_node#info(c93303b41ac66b6d).();
106 }
107
108 T* operatorcxx . . $ pvpgn/elist#iterator#`operator->`(5a2a78a048fb49a8).->() const {
109 return &ptrcxx . . $ pvpgn/elist#iterator#ptr.->infocxx . . $ pvpgn/elist_node#info(c93303b41ac66b6d).();
110 }
111
112 private:
113 elist_nodecxx . . $ pvpgn/elist_node#<T> *ptrcxx . . $ pvpgn/elist#iterator#ptr.;
114
115 explicit iteratorcxx . . $ pvpgn/elist#iterator#iterator(8d1f5d46ac8e2ad0).(elist_nodecxx . . $ pvpgn/elist_node#<T>* ptr_) : ptrcxx . . $ pvpgn/elist#iterator#ptr.(ptr_) {}
116 friend class elist;
117 };
118
119 explicit elistcxx . . $ pvpgn/elist#`elist<T>`(965cd0b40f950ebc).(elist_nodecxx . . $ pvpgn/elist_node#<T> T::* node_) : nodecxx . . $ pvpgn/elist#node.(node_) {}
120 ~cxx . . $ pvpgn/elist#`~elist<T>`(ced63f7c635d850d).elist() throw() {
121 clearcxx . . $ pvpgn/elist#clear(49f6e7a06ebc5aa8).();
122 }
123
124 void push_backcxx . . $ pvpgn/elist#push_back(8e935d9c2e576e3a).(T& obj) {
125 (obj.*nodecxx . . $ pvpgn/elist#node.).link_back(headcxx . . $ pvpgn/elist#head., obj);
126 }
127
128 void push_frontcxx . . $ pvpgn/elist#push_front(8e935d9c2e576e3a).(T& obj) {
129 (obj.*nodecxx . . $ pvpgn/elist#node.).link_front(headcxx . . $ pvpgn/elist#head., obj);
130 }
131
132 void removecxx . . $ pvpgn/elist#remove(8e935d9c2e576e3a).(T& obj) {
133 (obj.*nodecxx . . $ pvpgn/elist#node.).remove();
134 }
135
136 void removecxx . . $ pvpgn/elist#remove(1e8eb27d2759da73).(iteratorcxx . . $ pvpgn/elist#iterator#& it) {
137 it.ptrcxx . . $ pvpgn/elist#iterator#ptr.->remove();
138 }
139
140 void clearcxx . . $ pvpgn/elist#clear(49f6e7a06ebc5aa8).() {
141 while (!emptycxx . . $ pvpgn/elist#empty(c9857a73d68e59ba).())
142 headcxx . . $ pvpgn/elist#head..prevcxx . . $ pvpgn/elist_node#prev(2c7f7dc3e90659c9).()->remove();
143 }
144
145 bool emptycxx . . $ pvpgn/elist#empty(c9857a73d68e59ba).() {
146 return &headcxx . . $ pvpgn/elist#head. == headcxx . . $ pvpgn/elist#head..nextcxx . . $ pvpgn/elist_node#next(2c7f7dc3e90659c9).();
147 }
148
149 T& frontcxx . . $ pvpgn/elist#front(c93303b41ac66b6d).() const { return headcxx . . $ pvpgn/elist#head..nextcxx . . $ pvpgn/elist_node#next(2c7f7dc3e90659c9).()->info(); }
150 T& backcxx . . $ pvpgn/elist#back(c93303b41ac66b6d).() const { return headcxx . . $ pvpgn/elist#head..prevcxx . . $ pvpgn/elist_node#prev(2c7f7dc3e90659c9).()->info(); }
151
152 iteratorcxx . . $ pvpgn/elist#iterator# begincxx . . $ pvpgn/elist#begin(31f1ba2fb26ae483).() {
153 return iteratorcxx . . $ pvpgn/elist#iterator#(headcxx . . $ pvpgn/elist#head..nextcxx . . $ pvpgn/elist_node#next(2c7f7dc3e90659c9).());
154 }
155 iteratorcxx . . $ pvpgn/elist#iterator# endcxx . . $ pvpgn/elist#end(31f1ba2fb26ae483).() {
156 return iteratorcxx . . $ pvpgn/elist#iterator#(&headcxx . . $ pvpgn/elist#head.);
157 }
158
159 private:
160 /* the head of the list */
161 elist_nodecxx . . $ pvpgn/elist_node#<T> headcxx . . $ pvpgn/elist#head.;
162
163 /* used to access the elist_node<T> of a given T */
164 elist_nodecxx . . $ pvpgn/elist_node#<T> T::* nodecxx . . $ pvpgn/elist#node.;
165
166 elistcxx . . $ pvpgn/elist#`elist<T>`(bceb0cd82a1e850a).(const elist&);
167 elist& operatorcxx . . $ pvpgn/elist#`operator=`(fe3e09f430c6e4c6).=(const elist&);
168 };
169
170 typedef struct elist_structcxx . . $ pvpgn/elist_struct# {
171 struct elist_structcxx . . $ pvpgn/elist_struct# *nextcxx . . $ pvpgn/elist_struct#next., *prevcxx . . $ pvpgn/elist_struct#prev.;
172 } t_elistcxx . . $ pvpgn/t_elist#;
173
174 /* hlist are single linked elists */
175 typedef struct hlist_structcxx . . $ pvpgn/hlist_struct# {
176 struct hlist_structcxx . . $ pvpgn/hlist_struct# *nextcxx . . $ pvpgn/hlist_struct#next.;
177 } t_hlistcxx . . $ pvpgn/t_hlist#;
178
179 }
180
181 #endif /* INCLUDED_ELIST_TYPES */
182
183 #ifndef INCLUDED_ELIST_PROTOScxx . . $ `src/common/elist.h:184:9`!
184 #define INCLUDED_ELIST_PROTOScxx . . $ `src/common/elist.h:184:9`!
185
186 #include <cstddef>
187
188 /* access to it's members */
189 #define elist_nextcxx . . $ `src/common/elist.h:189:9`!(ptr) ((ptr)->next)
190 #define elist_prevcxx . . $ `src/common/elist.h:190:9`!(ptr) ((ptr)->prev)
191
192 #define __elist_initcxx . . $ `src/common/elist.h:192:9`!(elist,val) { (elist)->next = (elist)->prev = (val); }
193 #define elist_initcxx . . $ `src/common/elist.h:193:9`!(elist) __elist_initcxx . . $ `src/common/elist.h:192:9`!(elist,elist)
194 #define DECLARE_ELIST_INITcxx . . $ `src/common/elist.h:194:9`!(var) \
195 t_elist var = { &var, &var }
196
197 namespace pvpgncxx . . $ pvpgn/
198 {
199
200 /* link an new node just after "where" */
201 static inline void elist_addcxx . . $ pvpgn/elist_add(3e860e19053b2cfa).(t_elistcxx . . $ pvpgn/t_elist# *where, t_elistcxx . . $ pvpgn/t_elist# *what)
202 {
203 what->nextcxx . . $ pvpgn/elist_struct#next. = where->nextcxx . . $ pvpgn/elist_struct#next.;
204 where->nextcxx . . $ pvpgn/elist_struct#next.->prevcxx . . $ pvpgn/elist_struct#prev. = what;
205 what->prevcxx . . $ pvpgn/elist_struct#prev. = where;
206 where->nextcxx . . $ pvpgn/elist_struct#next. = what;
207 }
208
209 /* link a new node just before "where" (usefull in creating queues) */
210 static inline void elist_add_tailcxx . . $ pvpgn/elist_add_tail(3e860e19053b2cfa).(t_elistcxx . . $ pvpgn/t_elist# *where, t_elistcxx . . $ pvpgn/t_elist# *what)
211 {
212 what->prevcxx . . $ pvpgn/elist_struct#prev. = where->prevcxx . . $ pvpgn/elist_struct#prev.;
213 where->prevcxx . . $ pvpgn/elist_struct#prev.->nextcxx . . $ pvpgn/elist_struct#next. = what;
214 what->nextcxx . . $ pvpgn/elist_struct#next. = where;
215 where->prevcxx . . $ pvpgn/elist_struct#prev. = what;
216 }
217
218 /* unlink "what" from it's list */
219 static inline void elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(t_elistcxx . . $ pvpgn/t_elist# *what)
220 {
221 what->nextcxx . . $ pvpgn/elist_struct#next.->prevcxx . . $ pvpgn/elist_struct#prev. = what->prevcxx . . $ pvpgn/elist_struct#prev.;
222 what->prevcxx . . $ pvpgn/elist_struct#prev.->nextcxx . . $ pvpgn/elist_struct#next. = what->nextcxx . . $ pvpgn/elist_struct#next.;
223 }
224
225 /* finds out the container address by computing it from the list node
226 * address substracting the offset inside the container of the list node
227 * member */
228 #define elist_entrycxx . . $ `src/common/elist.h:228:9`!(ptr,type,member) ((type*)(((char*)ptr)-offsetofcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:431:9`!(type,member)))
229
230 /* DONT remove while traversing with this ! */
231 #define elist_for_eachcxx . . $ `src/common/elist.h:231:9`!(pos,head) \
232 for (pos = (head)->next; pos != (head); pos = pos->next)
233
234 #define elist_for_each_revcxx . . $ `src/common/elist.h:234:9`!(pos,head) \
235 for (pos = (head)->prev; pos != (head); pos = pos->prev)
236
237 /* safe for removals while traversing */
238 #define elist_for_each_safecxx . . $ `src/common/elist.h:238:9`!(pos,head,save) \
239 for (pos = (head)->next, save = pos->next; pos != (head); \
240 pos = save, save = pos->next)
241
242 #define elist_for_each_safe_revcxx . . $ `src/common/elist.h:242:9`!(pos,head,save) \
243 for (pos = (head)->prev, save = pos->prev; pos != (head); \
244 pos = save, save = pos->prev)
245
246 #define elist_emptycxx . . $ `src/common/elist.h:246:9`!(ptr) ((ptr)->next == (ptr))
247
248 #define hlist_nextcxx . . $ `src/common/elist.h:248:9`!(ptr) elist_next(ptr)
249
250 #define __hlist_initcxx . . $ `src/common/elist.h:250:9`!(hlist,val) { (hlist)->next = (val); }
251 #define hlist_initcxx . . $ `src/common/elist.h:251:9`!(hlist) __hlist_init(hlist,hlist)
252 #define DECLARE_HLIST_INITcxx . . $ `src/common/elist.h:252:9`!(var) \
253 t_hlist var = { &var };
254
255 /* link an new node just after "where" */
256 static inline void hlist_addcxx . . $ pvpgn/hlist_add(4bfba690b73acf43).(t_hlistcxx . . $ pvpgn/t_hlist# *where, t_hlistcxx . . $ pvpgn/t_hlist# *what)
257 {
258 what->nextcxx . . $ pvpgn/hlist_struct#next. = where->nextcxx . . $ pvpgn/hlist_struct#next.;
259 where->nextcxx . . $ pvpgn/hlist_struct#next. = what;
260 }
261
262 /* unlink "what" from it's list, prev->next = what */
263 static inline void hlist_delcxx . . $ pvpgn/hlist_del(4bfba690b73acf43).(t_hlistcxx . . $ pvpgn/t_hlist# *what, t_hlistcxx . . $ pvpgn/t_hlist# *prev)
264 {
265 prev->nextcxx . . $ pvpgn/hlist_struct#next. = what->nextcxx . . $ pvpgn/hlist_struct#next.;
266 }
267
268 /* move "what" back in the list with one position, never NULL
269 * prev: the previous element in the list, never NULL
270 * prev2: the previous element of "prev", if NULL means "what" is first
271 */
272 static inline void hlist_promotecxx . . $ pvpgn/hlist_promote(ffd20b3d36c8f483).(t_hlistcxx . . $ pvpgn/t_hlist# *what, t_hlistcxx . . $ pvpgn/t_hlist# *prev, t_hlistcxx . . $ pvpgn/t_hlist# *prev2)
273 {
274 if (prev2) {
275 prev->nextcxx . . $ pvpgn/hlist_struct#next. = what->nextcxx . . $ pvpgn/hlist_struct#next.;
276 prev2->nextcxx . . $ pvpgn/hlist_struct#next. = what;
277 what->nextcxx . . $ pvpgn/hlist_struct#next. = prev;
278 }
279 }
280
281 /* finds out the container address by computing it from the list node
282 * address substracting the offset inside the container of the list node
283 * member */
284 #define hlist_entrycxx . . $ `src/common/elist.h:284:9`!(ptr,type,member) elist_entry(ptr,type,member)
285
286 /* DONT remove while traversing with this ! */
287 #define hlist_for_eachcxx . . $ `src/common/elist.h:287:9`!(pos,head) elist_for_each(pos,head)
288
289 /* safe for removals while traversing */
290 #define hlist_for_each_safecxx . . $ `src/common/elist.h:290:9`!(pos,head,save) elist_for_each_safe(pos,head,save)
291
292 #define hlist_emptycxx . . $ `src/common/elist.h:292:9`!(ptr) elist_empty(ptr)
293
294 }
295
296 #endif /* INCLUDED_ELIST_PROTOS */