[Lemon-commits] [lemon_svn] deba: r2584 - hugo/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:53:43 CET 2006


Author: deba
Date: Mon Feb 27 11:36:01 2006
New Revision: 2584

Modified:
   hugo/trunk/lemon/full_graph.h
   hugo/trunk/lemon/grid_ugraph.h
   hugo/trunk/lemon/hypercube_graph.h

Log:
An additional simplier interface for static size graphs.
Node operator()(int) for getting node by index
int index(Node node) for getting index by node



Modified: hugo/trunk/lemon/full_graph.h
==============================================================================
--- hugo/trunk/lemon/full_graph.h	(original)
+++ hugo/trunk/lemon/full_graph.h	Mon Feb 27 11:36:01 2006
@@ -36,6 +36,9 @@
 
 namespace lemon {
 
+  /// \brief Base of the FullGrpah.
+  ///
+  /// Base of the FullGrpah.
   class FullGraphBase {
     int _nodeNum;
     int _edgeNum;
@@ -53,13 +56,26 @@
 
     ///Creates a full graph with \c n nodes.
     void construct(int n) { _nodeNum = n; _edgeNum = n * n; }
-    ///
-    //    FullGraphBase(const FullGraphBase &_g)
-    //      : _nodeNum(_g.nodeNum()), _edgeNum(_nodeNum*_nodeNum) { }
     
     typedef True NodeNumTag;
     typedef True EdgeNumTag;
 
+    /// \brief Returns the node with the given index.
+    ///
+    /// Returns the node with the given index. Because it is a
+    /// static size graph the node's of the graph can be indiced
+    /// by the range from 0 to \e nodeNum()-1 and the index of
+    /// the node can accessed by the \e index() member.
+    Node operator()(int index) const { return Node(index); }
+
+    /// \brief Returns the index of the node.
+    ///
+    /// Returns the index of the node. Because it is a
+    /// static size graph the node's of the graph can be indiced
+    /// by the range from 0 to \e nodeNum()-1 and the index of
+    /// the node can accessed by the \e index() member.
+    int index(const Node& node) const { return node.id; }
+
     ///Number of nodes.
     int nodeNum() const { return _nodeNum; }
     ///Number of edges.
@@ -202,6 +218,9 @@
   /// the \ref concept::StaticGraph "StaticGraph" concept
   /// \sa concept::StaticGraph.
   ///
+  /// \sa FullGraphBase
+  /// \sa FullUGraph
+  ///
   /// \author Alpar Juttner
   class FullGraph : public ExtendedFullGraphBase {
   public:
@@ -214,6 +233,9 @@
 
     /// \brief Resize the graph
     ///
+    /// Resize the graph. The function will fully destroy and build the graph.
+    /// This cause that the maps of the graph will reallocated
+    /// automatically and the previous values will be lost.
     void resize(int n) {
       Parent::getNotifier(Edge()).clear();
       Parent::getNotifier(Node()).clear();
@@ -224,6 +246,9 @@
   };
 
 
+  /// \brief Base of the FullUGrpah.
+  ///
+  /// Base of the FullUGrpah.
   class FullUGraphBase {
     int _nodeNum;
     int _edgeNum;
@@ -241,10 +266,23 @@
 
     ///Creates a full graph with \c n nodes.
     void construct(int n) { _nodeNum = n; _edgeNum = n * (n - 1) / 2; }
+
+    /// \brief Returns the node with the given index.
     ///
-    //    FullGraphBase(const FullGraphBase &_g)
-    //      : _nodeNum(_g.nodeNum()), _edgeNum(_nodeNum*_nodeNum) { }
-    
+    /// Returns the node with the given index. Because it is a
+    /// static size graph the node's of the graph can be indiced
+    /// by the range from 0 to \e nodeNum()-1 and the index of
+    /// the node can accessed by the \e index() member.
+    Node operator()(int index) const { return Node(index); }
+
+    /// \brief Returns the index of the node.
+    ///
+    /// Returns the index of the node. Because it is a
+    /// static size graph the node's of the graph can be indiced
+    /// by the range from 0 to \e nodeNum()-1 and the index of
+    /// the node can accessed by the \e index() member.
+    int index(const Node& node) const { return node.id; }
+
     typedef True NodeNumTag;
     typedef True EdgeNumTag;
 
@@ -275,18 +313,19 @@
     }
 
 
-    /// Node ID.
-    
+    /// \brief Node ID.
+    ///
     /// The ID of a valid Node is a nonnegative integer not greater than
     /// \ref maxNodeId(). The range of the ID's is not surely continuous
     /// and the greatest node ID can be actually less then \ref maxNodeId().
     ///
     /// The ID of the \ref INVALID node is -1.
-    ///\return The ID of the node \c v. 
+    /// \return The ID of the node \c v. 
 
     static int id(Node v) { return v.id; }
-    /// Edge ID.
-    
+
+    /// \brief Edge ID.
+    ///
     /// The ID of a valid Edge is a nonnegative integer not greater than
     /// \ref maxEdgeId(). The range of the ID's is not surely continuous
     /// and the greatest edge ID can be actually less then \ref maxEdgeId().
@@ -295,8 +334,8 @@
     ///\return The ID of the edge \c e. 
     static int id(Edge e) { return e.id; }
 
-    /// Finds an edge between two nodes.
-    
+    /// \brief Finds an edge between two nodes.
+    ///
     /// Finds an edge from node \c u to node \c v.
     ///
     /// If \c prev is \ref INVALID (this is the default value), then
@@ -304,7 +343,7 @@
     /// the next edge from \c u to \c v after \c prev.
     /// \return The found edge or INVALID if there is no such an edge.
     Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
-      if (prev.id != -1 || u.id <= v.id) return -1;
+      if (prev.id != -1 || u.id <= v.id) return Edge(-1);
       return Edge(u.id * (u.id - 1) / 2 + v.id);
     }
 
@@ -403,6 +442,7 @@
   /// is that this class conforms to the undirected graph concept and
   /// it does not contain the loop edges.
   ///
+  /// \sa FullUGraphBase
   /// \sa FullGraph
   ///
   /// \author Balazs Dezso
@@ -416,6 +456,9 @@
 
     /// \brief Resize the graph
     ///
+    /// Resize the graph. The function will fully destroy and build the graph.
+    /// This cause that the maps of the graph will reallocated
+    /// automatically and the previous values will be lost.
     void resize(int n) {
       Parent::getNotifier(Edge()).clear();
       Parent::getNotifier(UEdge()).clear();
@@ -612,6 +655,7 @@
   /// It is completely static, so you can neither add nor delete either
   /// edges or nodes.
   ///
+  /// \sa FullUGraphBase
   /// \sa FullGraph
   ///
   /// \author Balazs Dezso

Modified: hugo/trunk/lemon/grid_ugraph.h
==============================================================================
--- hugo/trunk/lemon/grid_ugraph.h	(original)
+++ hugo/trunk/lemon/grid_ugraph.h	Mon Feb 27 11:36:01 2006
@@ -126,7 +126,8 @@
     /// 
     /// Gives back the node on the given position.
     Node operator()(int i, int j) const {
-      LEMON_ASSERT(0 <= i && i < width() && 0 <= j  && j < height(), IndexError());
+      LEMON_ASSERT(0 <= i && i < width() && 0 <= j  && 
+                   j < height(), IndexError());
       return Node(i + j * _width);
     }
 

Modified: hugo/trunk/lemon/hypercube_graph.h
==============================================================================
--- hugo/trunk/lemon/hypercube_graph.h	(original)
+++ hugo/trunk/lemon/hypercube_graph.h	Mon Feb 27 11:36:01 2006
@@ -224,7 +224,7 @@
     /// \brief Gives back the node by its index.
     ///
     ///  Gives back the node by its index.
-    Node node(int index) const {
+    Node operator()(int index) const {
       return Node(index);
     }
     



More information about the Lemon-commits mailing list