1.1 --- a/lemon/static_graph.h Tue Aug 25 11:09:02 2009 +0200
1.2 +++ b/lemon/static_graph.h Tue Aug 25 13:58:43 2009 +0200
1.3 @@ -32,13 +32,13 @@
1.4 public:
1.5
1.6 StaticDigraphBase()
1.7 - : node_num(-1), arc_num(0),
1.8 + : built(false), node_num(0), arc_num(0),
1.9 node_first_out(NULL), node_first_in(NULL),
1.10 arc_source(NULL), arc_target(NULL),
1.11 arc_next_in(NULL), arc_next_out(NULL) {}
1.12
1.13 ~StaticDigraphBase() {
1.14 - if (node_num != -1) {
1.15 + if (built) {
1.16 delete[] node_first_out;
1.17 delete[] node_first_in;
1.18 delete[] arc_source;
1.19 @@ -128,10 +128,8 @@
1.20
1.21 typedef True BuildTag;
1.22
1.23 - template <typename Digraph, typename NodeRefMap, typename ArcRefMap>
1.24 - void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
1.25 -
1.26 - if (node_num != -1) {
1.27 + void clear() {
1.28 + if (built) {
1.29 delete[] node_first_out;
1.30 delete[] node_first_in;
1.31 delete[] arc_source;
1.32 @@ -139,10 +137,18 @@
1.33 delete[] arc_next_out;
1.34 delete[] arc_next_in;
1.35 }
1.36 -
1.37 + built = false;
1.38 + node_num = 0;
1.39 + arc_num = 0;
1.40 + }
1.41 +
1.42 + template <typename Digraph, typename NodeRefMap, typename ArcRefMap>
1.43 + void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
1.44 typedef typename Digraph::Node GNode;
1.45 typedef typename Digraph::Arc GArc;
1.46
1.47 + built = true;
1.48 +
1.49 node_num = countNodes(digraph);
1.50 arc_num = countArcs(digraph);
1.51
1.52 @@ -205,7 +211,8 @@
1.53 e.id = node_first_out[n.id + 1];
1.54 }
1.55
1.56 - private:
1.57 + protected:
1.58 + bool built;
1.59 int node_num;
1.60 int arc_num;
1.61 int *node_first_out;
1.62 @@ -223,6 +230,15 @@
1.63 public:
1.64
1.65 typedef ExtendedStaticDigraphBase Parent;
1.66 +
1.67 + public:
1.68 +
1.69 + template <typename Digraph, typename NodeRefMap, typename ArcRefMap>
1.70 + void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
1.71 + if (built) Parent::clear();
1.72 + Parent::build(digraph, nodeRef, arcRef);
1.73 + }
1.74 +
1.75
1.76 protected:
1.77
1.78 @@ -261,6 +277,22 @@
1.79 Arc last;
1.80 };
1.81
1.82 + Node baseNode(const OutArcIt &arc) const {
1.83 + return Parent::source(static_cast<const Arc&>(arc));
1.84 + }
1.85 +
1.86 + Node runningNode(const OutArcIt &arc) const {
1.87 + return Parent::target(static_cast<const Arc&>(arc));
1.88 + }
1.89 +
1.90 + Node baseNode(const InArcIt &arc) const {
1.91 + return Parent::target(static_cast<const Arc&>(arc));
1.92 + }
1.93 +
1.94 + Node runningNode(const InArcIt &arc) const {
1.95 + return Parent::source(static_cast<const Arc&>(arc));
1.96 + }
1.97 +
1.98 };
1.99
1.100 }