# HG changeset patch
# User Gabriel Gouvine <gabriel.gouvine.GIT@gmx.com>
# Date 1488481030 -3600
# Thu Mar 02 19:57:10 2017 +0100
# Node ID b127b5408042aebd5f559a888d807fa4e596d61e
# Parent fd04b9f2058dc6979eb27fe01835b9e5c38e9034
Remove arc_next_out from StaticDigraphBase
* Was only used in DigraphExtender::OutArcIt, overwritten in StaticDigraph
* Space complexity is now 2n + 3m (from 2n + 4m)
* nextOut(Arc &) redefined for compatibility
diff -r fd04b9f2058d -r b127b5408042 lemon/static_graph.h
a
|
b
|
|
36 | 36 | : built(false), node_num(0), arc_num(0), |
37 | 37 | node_first_out(NULL), node_first_in(NULL), |
38 | 38 | arc_source(NULL), arc_target(NULL), |
39 | | arc_next_in(NULL), arc_next_out(NULL) {} |
| 39 | arc_next_in(NULL) {} |
40 | 40 | |
41 | 41 | ~StaticDigraphBase() { |
42 | 42 | if (built) { |
… |
… |
|
44 | 44 | delete[] node_first_in; |
45 | 45 | delete[] arc_source; |
46 | 46 | delete[] arc_target; |
47 | | delete[] arc_next_out; |
48 | 47 | delete[] arc_next_in; |
49 | 48 | } |
50 | 49 | } |
… |
… |
|
88 | 87 | e.id = node_first_out[n.id] != node_first_out[n.id + 1] ? |
89 | 88 | node_first_out[n.id] : -1; |
90 | 89 | } |
91 | | void nextOut(Arc& e) const { e.id = arc_next_out[e.id]; } |
| 90 | void nextOut(Arc& e) const { |
| 91 | Node n = source(e); |
| 92 | Arc last; |
| 93 | fastLastOut(last, n); |
| 94 | ++e.id; |
| 95 | if (e == last) e.id = -1; |
| 96 | } |
92 | 97 | |
93 | 98 | void firstIn(Arc& e, const Node& n) const { e.id = node_first_in[n.id]; } |
94 | 99 | void nextIn(Arc& e) const { e.id = arc_next_in[e.id]; } |
… |
… |
|
135 | 140 | delete[] node_first_in; |
136 | 141 | delete[] arc_source; |
137 | 142 | delete[] arc_target; |
138 | | delete[] arc_next_out; |
139 | 143 | delete[] arc_next_in; |
140 | 144 | } |
141 | 145 | built = false; |
… |
… |
|
158 | 162 | |
159 | 163 | arc_source = new int[arc_num]; |
160 | 164 | arc_target = new int[arc_num]; |
161 | | arc_next_out = new int[arc_num]; |
162 | 165 | arc_next_in = new int[arc_num]; |
163 | 166 | |
164 | 167 | int node_index = 0; |
… |
… |
|
188 | 191 | arc_target[arc_index] = target; |
189 | 192 | arc_next_in[arc_index] = node_first_in[target]; |
190 | 193 | node_first_in[target] = arc_index; |
191 | | arc_next_out[arc_index] = arc_index + 1; |
192 | 194 | ++arc_index; |
193 | 195 | } |
194 | | arc_next_out[arc_index - 1] = -1; |
195 | 196 | } else { |
196 | 197 | node_first_out[source] = arc_index; |
197 | 198 | } |
… |
… |
|
211 | 212 | |
212 | 213 | arc_source = new int[arc_num]; |
213 | 214 | arc_target = new int[arc_num]; |
214 | | arc_next_out = new int[arc_num]; |
215 | 215 | arc_next_in = new int[arc_num]; |
216 | 216 | |
217 | 217 | for (int i = 0; i != node_num; ++i) { |
… |
… |
|
229 | 229 | arc_target[arc_index] = j; |
230 | 230 | arc_next_in[arc_index] = node_first_in[j]; |
231 | 231 | node_first_in[j] = arc_index; |
232 | | arc_next_out[arc_index] = arc_index + 1; |
233 | 232 | ++arc_index; |
234 | 233 | } |
235 | | if (arc_index > node_first_out[i]) |
236 | | arc_next_out[arc_index - 1] = -1; |
237 | 234 | } |
238 | 235 | LEMON_ASSERT(first == last, |
239 | 236 | "Wrong arc list for StaticDigraph::build()"); |
… |
… |
|
262 | 259 | int *arc_source; |
263 | 260 | int *arc_target; |
264 | 261 | int *arc_next_in; |
265 | | int *arc_next_out; |
266 | 262 | }; |
267 | 263 | |
268 | 264 | typedef DigraphExtender<StaticDigraphBase> ExtendedStaticDigraphBase; |