diff --git a/lemon/static_graph.h b/lemon/static_graph.h --- a/lemon/static_graph.h +++ b/lemon/static_graph.h @@ -32,13 +32,13 @@ public: StaticDigraphBase() - : node_num(-1), arc_num(0), + : built(false), node_num(0), arc_num(0), node_first_out(NULL), node_first_in(NULL), arc_source(NULL), arc_target(NULL), arc_next_in(NULL), arc_next_out(NULL) {} ~StaticDigraphBase() { - if (node_num != -1) { + if (built) { delete[] node_first_out; delete[] node_first_in; delete[] arc_source; @@ -128,10 +128,8 @@ typedef True BuildTag; - template - void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { - - if (node_num != -1) { + void clear() { + if (built) { delete[] node_first_out; delete[] node_first_in; delete[] arc_source; @@ -139,10 +137,18 @@ delete[] arc_next_out; delete[] arc_next_in; } - + built = false; + node_num = 0; + arc_num = 0; + } + + template + void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { typedef typename Digraph::Node GNode; typedef typename Digraph::Arc GArc; + built = true; + node_num = countNodes(digraph); arc_num = countArcs(digraph); @@ -205,7 +211,8 @@ e.id = node_first_out[n.id + 1]; } - private: + protected: + bool built; int node_num; int arc_num; int *node_first_out; @@ -223,6 +230,15 @@ public: typedef ExtendedStaticDigraphBase Parent; + + public: + + template + void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { + if (built) Parent::clear(); + Parent::build(digraph, nodeRef, arcRef); + } + protected: @@ -261,6 +277,22 @@ Arc last; }; + Node baseNode(const OutArcIt &arc) const { + return Parent::source(static_cast(arc)); + } + + Node runningNode(const OutArcIt &arc) const { + return Parent::target(static_cast(arc)); + } + + Node baseNode(const InArcIt &arc) const { + return Parent::target(static_cast(arc)); + } + + Node runningNode(const InArcIt &arc) const { + return Parent::source(static_cast(arc)); + } + }; }