30 |
30 |
31 class StaticDigraphBase { |
31 class StaticDigraphBase { |
32 public: |
32 public: |
33 |
33 |
34 StaticDigraphBase() |
34 StaticDigraphBase() |
35 : node_num(-1), arc_num(0), |
35 : built(false), node_num(0), arc_num(0), |
36 node_first_out(NULL), node_first_in(NULL), |
36 node_first_out(NULL), node_first_in(NULL), |
37 arc_source(NULL), arc_target(NULL), |
37 arc_source(NULL), arc_target(NULL), |
38 arc_next_in(NULL), arc_next_out(NULL) {} |
38 arc_next_in(NULL), arc_next_out(NULL) {} |
39 |
39 |
40 ~StaticDigraphBase() { |
40 ~StaticDigraphBase() { |
41 if (node_num != -1) { |
41 if (built) { |
42 delete[] node_first_out; |
42 delete[] node_first_out; |
43 delete[] node_first_in; |
43 delete[] node_first_in; |
44 delete[] arc_source; |
44 delete[] arc_source; |
45 delete[] arc_target; |
45 delete[] arc_target; |
46 delete[] arc_next_out; |
46 delete[] arc_next_out; |
126 |
126 |
127 public: |
127 public: |
128 |
128 |
129 typedef True BuildTag; |
129 typedef True BuildTag; |
130 |
130 |
131 template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
131 void clear() { |
132 void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { |
132 if (built) { |
133 |
|
134 if (node_num != -1) { |
|
135 delete[] node_first_out; |
133 delete[] node_first_out; |
136 delete[] node_first_in; |
134 delete[] node_first_in; |
137 delete[] arc_source; |
135 delete[] arc_source; |
138 delete[] arc_target; |
136 delete[] arc_target; |
139 delete[] arc_next_out; |
137 delete[] arc_next_out; |
140 delete[] arc_next_in; |
138 delete[] arc_next_in; |
141 } |
139 } |
142 |
140 built = false; |
|
141 node_num = 0; |
|
142 arc_num = 0; |
|
143 } |
|
144 |
|
145 template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
|
146 void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { |
143 typedef typename Digraph::Node GNode; |
147 typedef typename Digraph::Node GNode; |
144 typedef typename Digraph::Arc GArc; |
148 typedef typename Digraph::Arc GArc; |
|
149 |
|
150 built = true; |
145 |
151 |
146 node_num = countNodes(digraph); |
152 node_num = countNodes(digraph); |
147 arc_num = countArcs(digraph); |
153 arc_num = countArcs(digraph); |
148 |
154 |
149 node_first_out = new int[node_num + 1]; |
155 node_first_out = new int[node_num + 1]; |
221 |
228 |
222 class StaticDigraph : public ExtendedStaticDigraphBase { |
229 class StaticDigraph : public ExtendedStaticDigraphBase { |
223 public: |
230 public: |
224 |
231 |
225 typedef ExtendedStaticDigraphBase Parent; |
232 typedef ExtendedStaticDigraphBase Parent; |
|
233 |
|
234 public: |
|
235 |
|
236 template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
|
237 void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { |
|
238 if (built) Parent::clear(); |
|
239 Parent::build(digraph, nodeRef, arcRef); |
|
240 } |
|
241 |
226 |
242 |
227 protected: |
243 protected: |
228 |
244 |
229 using Parent::fastFirstOut; |
245 using Parent::fastFirstOut; |
230 using Parent::fastNextOut; |
246 using Parent::fastNextOut; |