[Lemon-commits] Peter Kovacs: Using from-to order in graph copyi...

Lemon HG hg at lemon.cs.elte.hu
Sun Sep 28 11:15:11 CEST 2008


details:   http://lemon.cs.elte.hu/hg/lemon/rev/dc9e8d2c0df9
changeset: 282:dc9e8d2c0df9
user:      Peter Kovacs <kpeter [at] inf.elte.hu>
date:      Fri Sep 26 13:46:49 2008 +0200
description:
	Using from-to order in graph copying tools + doc improvements
	(ticket #150)

diffstat:

2 files changed, 331 insertions(+), 315 deletions(-)
lemon/core.h            |  634 ++++++++++++++++++++++++-----------------------
test/graph_copy_test.cc |   12 

diffs (truncated from 1345 to 300 lines):

diff -r 6307bbbf285b -r dc9e8d2c0df9 lemon/core.h
--- a/lemon/core.h	Tue Sep 23 18:42:49 2008 +0200
+++ b/lemon/core.h	Fri Sep 26 13:46:49 2008 +0200
@@ -58,10 +58,10 @@
   /// \addtogroup gutils
   /// @{
 
-  ///Creates convenience typedefs for the digraph types and iterators
+  ///Create convenient typedefs for the digraph types and iterators
 
-  ///This \c \#define creates convenience typedefs for the following types
-  ///of \c Digraph: \c Node,  \c NodeIt, \c Arc, \c ArcIt, \c InArcIt,
+  ///This \c \#define creates convenient type definitions for the following
+  ///types of \c Digraph: \c Node,  \c NodeIt, \c Arc, \c ArcIt, \c InArcIt,
   ///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap,
   ///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap.
   ///
@@ -80,9 +80,9 @@
   typedef Digraph::NodeMap<double> DoubleNodeMap;                       \
   typedef Digraph::ArcMap<bool> BoolArcMap;                             \
   typedef Digraph::ArcMap<int> IntArcMap;                               \
-  typedef Digraph::ArcMap<double> DoubleArcMap
+  typedef Digraph::ArcMap<double> DoubleArcMap;
 
-  ///Creates convenience typedefs for the digraph types and iterators
+  ///Create convenient typedefs for the digraph types and iterators
 
   ///\see DIGRAPH_TYPEDEFS
   ///
@@ -100,17 +100,17 @@
   typedef typename Digraph::template NodeMap<double> DoubleNodeMap;     \
   typedef typename Digraph::template ArcMap<bool> BoolArcMap;           \
   typedef typename Digraph::template ArcMap<int> IntArcMap;             \
-  typedef typename Digraph::template ArcMap<double> DoubleArcMap
+  typedef typename Digraph::template ArcMap<double> DoubleArcMap;
 
-  ///Creates convenience typedefs for the graph types and iterators
+  ///Create convenient typedefs for the graph types and iterators
 
-  ///This \c \#define creates the same convenience typedefs as defined
+  ///This \c \#define creates the same convenient type definitions as defined
   ///by \ref DIGRAPH_TYPEDEFS(Graph) and six more, namely it creates
   ///\c Edge, \c EdgeIt, \c IncEdgeIt, \c BoolEdgeMap, \c IntEdgeMap,
   ///\c DoubleEdgeMap.
   ///
   ///\note If the graph type is a dependent type, ie. the graph type depend
-  ///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS()
+  ///on a template parameter, then use \c TEMPLATE_GRAPH_TYPEDEFS()
   ///macro.
 #define GRAPH_TYPEDEFS(Graph)                                           \
   DIGRAPH_TYPEDEFS(Graph);                                              \
@@ -119,9 +119,9 @@
   typedef Graph::IncEdgeIt IncEdgeIt;                                   \
   typedef Graph::EdgeMap<bool> BoolEdgeMap;                             \
   typedef Graph::EdgeMap<int> IntEdgeMap;                               \
-  typedef Graph::EdgeMap<double> DoubleEdgeMap
+  typedef Graph::EdgeMap<double> DoubleEdgeMap;
 
-  ///Creates convenience typedefs for the graph types and iterators
+  ///Create convenient typedefs for the graph types and iterators
 
   ///\see GRAPH_TYPEDEFS
   ///
@@ -134,12 +134,12 @@
   typedef typename Graph::IncEdgeIt IncEdgeIt;                          \
   typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;           \
   typedef typename Graph::template EdgeMap<int> IntEdgeMap;             \
-  typedef typename Graph::template EdgeMap<double> DoubleEdgeMap
+  typedef typename Graph::template EdgeMap<double> DoubleEdgeMap;
 
-  /// \brief Function to count the items in the graph.
+  /// \brief Function to count the items in a graph.
   ///
-  /// This function counts the items (nodes, arcs etc) in the graph.
-  /// The complexity of the function is O(n) because
+  /// This function counts the items (nodes, arcs etc.) in a graph.
+  /// The complexity of the function is linear because
   /// it iterates on all of the items.
   template <typename Graph, typename Item>
   inline int countItems(const Graph& g) {
@@ -176,11 +176,11 @@
   /// \brief Function to count the nodes in the graph.
   ///
   /// This function counts the nodes in the graph.
-  /// The complexity of the function is O(n) but for some
-  /// graph structures it is specialized to run in O(1).
+  /// The complexity of the function is <em>O</em>(<em>n</em>), but for some
+  /// graph structures it is specialized to run in <em>O</em>(1).
   ///
-  /// If the graph contains a \e nodeNum() member function and a
-  /// \e NodeNumTag tag then this function calls directly the member
+  /// \note If the graph contains a \c nodeNum() member function and a
+  /// \c NodeNumTag tag then this function calls directly the member
   /// function to query the cardinality of the node set.
   template <typename Graph>
   inline int countNodes(const Graph& g) {
@@ -212,11 +212,11 @@
   /// \brief Function to count the arcs in the graph.
   ///
   /// This function counts the arcs in the graph.
-  /// The complexity of the function is O(e) but for some
-  /// graph structures it is specialized to run in O(1).
+  /// The complexity of the function is <em>O</em>(<em>m</em>), but for some
+  /// graph structures it is specialized to run in <em>O</em>(1).
   ///
-  /// If the graph contains a \e arcNum() member function and a
-  /// \e EdgeNumTag tag then this function calls directly the member
+  /// \note If the graph contains a \c arcNum() member function and a
+  /// \c ArcNumTag tag then this function calls directly the member
   /// function to query the cardinality of the arc set.
   template <typename Graph>
   inline int countArcs(const Graph& g) {
@@ -224,6 +224,7 @@
   }
 
   // Edge counting:
+
   namespace _core_bits {
 
     template <typename Graph, typename Enable = void>
@@ -247,11 +248,11 @@
   /// \brief Function to count the edges in the graph.
   ///
   /// This function counts the edges in the graph.
-  /// The complexity of the function is O(m) but for some
-  /// graph structures it is specialized to run in O(1).
+  /// The complexity of the function is <em>O</em>(<em>m</em>), but for some
+  /// graph structures it is specialized to run in <em>O</em>(1).
   ///
-  /// If the graph contains a \e edgeNum() member function and a
-  /// \e EdgeNumTag tag then this function calls directly the member
+  /// \note If the graph contains a \c edgeNum() member function and a
+  /// \c EdgeNumTag tag then this function calls directly the member
   /// function to query the cardinality of the edge set.
   template <typename Graph>
   inline int countEdges(const Graph& g) {
@@ -272,28 +273,28 @@
   /// \brief Function to count the number of the out-arcs from node \c n.
   ///
   /// This function counts the number of the out-arcs from node \c n
-  /// in the graph.
+  /// in the graph \c g.
   template <typename Graph>
-  inline int countOutArcs(const Graph& _g,  const typename Graph::Node& _n) {
-    return countNodeDegree<Graph, typename Graph::OutArcIt>(_g, _n);
+  inline int countOutArcs(const Graph& g,  const typename Graph::Node& n) {
+    return countNodeDegree<Graph, typename Graph::OutArcIt>(g, n);
   }
 
   /// \brief Function to count the number of the in-arcs to node \c n.
   ///
   /// This function counts the number of the in-arcs to node \c n
-  /// in the graph.
+  /// in the graph \c g.
   template <typename Graph>
-  inline int countInArcs(const Graph& _g,  const typename Graph::Node& _n) {
-    return countNodeDegree<Graph, typename Graph::InArcIt>(_g, _n);
+  inline int countInArcs(const Graph& g,  const typename Graph::Node& n) {
+    return countNodeDegree<Graph, typename Graph::InArcIt>(g, n);
   }
 
   /// \brief Function to count the number of the inc-edges to node \c n.
   ///
   /// This function counts the number of the inc-edges to node \c n
-  /// in the graph.
+  /// in the undirected graph \c g.
   template <typename Graph>
-  inline int countIncEdges(const Graph& _g,  const typename Graph::Node& _n) {
-    return countNodeDegree<Graph, typename Graph::IncEdgeIt>(_g, _n);
+  inline int countIncEdges(const Graph& g,  const typename Graph::Node& n) {
+    return countNodeDegree<Graph, typename Graph::IncEdgeIt>(g, n);
   }
 
   namespace _core_bits {
@@ -307,12 +308,12 @@
     };
 
     template <typename Digraph, typename Item, typename RefMap,
-              typename ToMap, typename FromMap>
+              typename FromMap, typename ToMap>
     class MapCopy : public MapCopyBase<Digraph, Item, RefMap> {
     public:
 
-      MapCopy(ToMap& tmap, const FromMap& map)
-        : _tmap(tmap), _map(map) {}
+      MapCopy(const FromMap& map, ToMap& tmap)
+        : _map(map), _tmap(tmap) {}
 
       virtual void copy(const Digraph& digraph, const RefMap& refMap) {
         typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt;
@@ -322,23 +323,23 @@
       }
 
     private:
+      const FromMap& _map;
       ToMap& _tmap;
-      const FromMap& _map;
     };
 
     template <typename Digraph, typename Item, typename RefMap, typename It>
     class ItemCopy : public MapCopyBase<Digraph, Item, RefMap> {
     public:
 
-      ItemCopy(It& it, const Item& item) : _it(it), _item(item) {}
+      ItemCopy(const Item& item, It& it) : _item(item), _it(it) {}
 
       virtual void copy(const Digraph&, const RefMap& refMap) {
         _it = refMap[_item];
       }
 
     private:
+      Item _item;
       It& _it;
-      Item _item;
     };
 
     template <typename Digraph, typename Item, typename RefMap, typename Ref>
@@ -379,7 +380,7 @@
     template <typename Digraph, typename Enable = void>
     struct DigraphCopySelector {
       template <typename From, typename NodeRefMap, typename ArcRefMap>
-      static void copy(Digraph &to, const From& from,
+      static void copy(const From& from, Digraph &to,
                        NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) {
         for (typename From::NodeIt it(from); it != INVALID; ++it) {
           nodeRefMap[it] = to.addNode();
@@ -397,7 +398,7 @@
       typename enable_if<typename Digraph::BuildTag, void>::type>
     {
       template <typename From, typename NodeRefMap, typename ArcRefMap>
-      static void copy(Digraph &to, const From& from,
+      static void copy(const From& from, Digraph &to,
                        NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) {
         to.build(from, nodeRefMap, arcRefMap);
       }
@@ -406,7 +407,7 @@
     template <typename Graph, typename Enable = void>
     struct GraphCopySelector {
       template <typename From, typename NodeRefMap, typename EdgeRefMap>
-      static void copy(Graph &to, const From& from,
+      static void copy(const From& from, Graph &to,
                        NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
         for (typename From::NodeIt it(from); it != INVALID; ++it) {
           nodeRefMap[it] = to.addNode();
@@ -424,7 +425,7 @@
       typename enable_if<typename Graph::BuildTag, void>::type>
     {
       template <typename From, typename NodeRefMap, typename EdgeRefMap>
-      static void copy(Graph &to, const From& from,
+      static void copy(const From& from, Graph &to,
                        NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
         to.build(from, nodeRefMap, edgeRefMap);
       }
@@ -435,39 +436,39 @@
   /// \brief Class to copy a digraph.
   ///
   /// Class to copy a digraph to another digraph (duplicate a digraph). The
-  /// simplest way of using it is through the \c copyDigraph() function.
+  /// simplest way of using it is through the \c digraphCopy() function.
   ///
-  /// This class not just make a copy of a graph, but it can create
+  /// This class not only make a copy of a digraph, but it can create
   /// references and cross references between the nodes and arcs of
-  /// the two graphs, it can copy maps for use with the newly created
-  /// graph and copy nodes and arcs.
+  /// the two digraphs, and it can copy maps to use with the newly created
+  /// digraph.
   ///
-  /// To make a copy from a graph, first an instance of DigraphCopy
-  /// should be created, then the data belongs to the graph should
+  /// To make a copy from a digraph, first an instance of DigraphCopy
+  /// should be created, then the data belongs to the digraph should
   /// assigned to copy. In the end, the \c run() member should be
   /// called.
   ///
-  /// The next code copies a graph with several data:
+  /// The next code copies a digraph with several data:
   ///\code
-  ///  DigraphCopy<NewGraph, OrigGraph> dc(new_graph, orig_graph);
-  ///  // create a reference for the nodes
+  ///  DigraphCopy<OrigGraph, NewGraph> cg(orig_graph, new_graph);
+  ///  // Create references for the nodes
   ///  OrigGraph::NodeMap<NewGraph::Node> nr(orig_graph);
-  ///  dc.nodeRef(nr);
-  ///  // create a cross reference (inverse) for the arcs
+  ///  cg.nodeRef(nr);
+  ///  // Create cross references (inverse) for the arcs
   ///  NewGraph::ArcMap<OrigGraph::Arc> acr(new_graph);
-  ///  dc.arcCrossRef(acr);
-  ///  // copy an arc map
+  ///  cg.arcCrossRef(acr);
+  ///  // Copy an arc map
   ///  OrigGraph::ArcMap<double> oamap(orig_graph);
   ///  NewGraph::ArcMap<double> namap(new_graph);
-  ///  dc.arcMap(namap, oamap);
-  ///  // copy a node
+  ///  cg.arcMap(oamap, namap);
+  ///  // Copy a node
   ///  OrigGraph::Node on;
   ///  NewGraph::Node nn;



More information about the Lemon-commits mailing list