# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1251216059 -7200
# Node ID a3de05c56e7e87f6c030016f32ba7ef664519f70
# Parent 6cab2ab9d8e7df5a77ddbadbb4dabb920f9a913e
Remove the outgoing arc list from StaticDigraph (#68)
to save one int value for each arc.
The list was used only by the basic iteration interface, i.e.
the nextOut(Arc&) function, but it can be implemented easily
and efficiently without the outgoing arc list, as well.
diff --git a/lemon/static_graph.h b/lemon/static_graph.h
a
|
b
|
|
34 | 34 | StaticDigraphBase() |
35 | 35 | : built(false), node_num(0), arc_num(0), |
36 | 36 | node_first_out(NULL), node_first_in(NULL), |
37 | | arc_source(NULL), arc_target(NULL), |
38 | | arc_next_in(NULL), arc_next_out(NULL) {} |
| 37 | arc_source(NULL), arc_target(NULL), arc_next_in(NULL) {} |
39 | 38 | |
40 | 39 | ~StaticDigraphBase() { |
41 | 40 | if (built) { |
… |
… |
|
43 | 42 | delete[] node_first_in; |
44 | 43 | delete[] arc_source; |
45 | 44 | delete[] arc_target; |
46 | | delete[] arc_next_out; |
47 | 45 | delete[] arc_next_in; |
48 | 46 | } |
49 | 47 | } |
… |
… |
|
87 | 85 | e.id = node_first_out[n.id] != node_first_out[n.id + 1] ? |
88 | 86 | node_first_out[n.id] : -1; |
89 | 87 | } |
90 | | void nextOut(Arc& e) const { e.id = arc_next_out[e.id]; } |
| 88 | void nextOut(Arc& e) const { |
| 89 | e.id = e.id + 1 != node_first_out[arc_source[e.id] + 1] ? |
| 90 | e.id + 1 : -1; |
| 91 | } |
91 | 92 | |
92 | 93 | void firstIn(Arc& e, const Node& n) const { e.id = node_first_in[n.id]; } |
93 | 94 | void nextIn(Arc& e) const { e.id = arc_next_in[e.id]; } |
… |
… |
|
134 | 135 | delete[] node_first_in; |
135 | 136 | delete[] arc_source; |
136 | 137 | delete[] arc_target; |
137 | | delete[] arc_next_out; |
138 | 138 | delete[] arc_next_in; |
139 | 139 | } |
140 | 140 | built = false; |
… |
… |
|
157 | 157 | |
158 | 158 | arc_source = new int[arc_num]; |
159 | 159 | arc_target = new int[arc_num]; |
160 | | arc_next_out = new int[arc_num]; |
161 | 160 | arc_next_in = new int[arc_num]; |
162 | 161 | |
163 | 162 | int node_index = 0; |
… |
… |
|
187 | 186 | arc_target[arc_index] = target; |
188 | 187 | arc_next_in[arc_index] = node_first_in[target]; |
189 | 188 | node_first_in[target] = arc_index; |
190 | | arc_next_out[arc_index] = arc_index + 1; |
191 | 189 | ++arc_index; |
192 | 190 | } |
193 | | arc_next_out[arc_index - 1] = -1; |
194 | 191 | } else { |
195 | 192 | node_first_out[source] = arc_index; |
196 | 193 | } |
… |
… |
|
220 | 217 | int *arc_source; |
221 | 218 | int *arc_target; |
222 | 219 | int *arc_next_in; |
223 | | int *arc_next_out; |
224 | 220 | }; |
225 | 221 | |
226 | 222 | typedef DigraphExtender<StaticDigraphBase> ExtendedStaticDigraphBase; |
… |
… |
|
232 | 228 | /// |
233 | 229 | /// \ref StaticDigraph is a highly efficient digraph implementation, |
234 | 230 | /// but it is fully static. |
235 | | /// It stores only two \c int values for each node and only four \c int |
| 231 | /// It stores only two \c int values for each node and only three \c int |
236 | 232 | /// values for each arc. Moreover it provides faster item iteration than |
237 | 233 | /// \ref ListDigraph and \ref SmartDigraph, especially using \c OutArcIt |
238 | 234 | /// iterators, since its arcs are stored in an appropriate order. |