[Lemon-commits] Peter Kovacs: Extend the interface of StaticDigr...
Lemon HG
hg at lemon.cs.elte.hu
Thu Nov 5 10:24:28 CET 2009
details: http://lemon.cs.elte.hu/hg/lemon/rev/eff1caf6d32e
changeset: 836:eff1caf6d32e
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Tue Sep 29 10:39:20 2009 +0200
description:
Extend the interface of StaticDigraph (#68) with index(), arc() and
node() functions similarly to other static graph structures.
diffstat:
lemon/static_graph.h | 58 ++++++++++++++++++++++++++---
test/digraph_test.cc | 5 ++
2 files changed, 57 insertions(+), 6 deletions(-)
diffs (98 lines):
diff --git a/lemon/static_graph.h b/lemon/static_graph.h
--- a/lemon/static_graph.h
+++ b/lemon/static_graph.h
@@ -239,6 +239,14 @@
/// However it only provides build() and clear() functions and does not
/// support any other modification of the digraph.
///
+ /// Since this digraph structure is completely static, its nodes and arcs
+ /// can be indexed with integers from the ranges <tt>[0..nodeNum()-1]</tt>
+ /// and <tt>[0..arcNum()-1]</tt>, respectively.
+ /// The index of an item is the same as its ID, it can be obtained
+ /// using the corresponding \ref index() or \ref concepts::Digraph::id()
+ /// "id()" function. A node or arc with a certain index can be obtained
+ /// using node() or arc().
+ ///
/// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
/// Most of its member functions and nested classes are documented
/// only in the concept class.
@@ -251,13 +259,45 @@
public:
- /// \brief Clear the digraph.
+ /// \brief Constructor
///
- /// This function erases all nodes and arcs from the digraph.
- void clear() {
- Parent::clear();
- }
-
+ /// Default constructor.
+ StaticDigraph() : Parent() {}
+
+ /// \brief The node with the given index.
+ ///
+ /// This function returns the node with the given index.
+ /// \sa index()
+ Node node(int ix) const { return Parent::nodeFromId(ix); }
+
+ /// \brief The arc with the given index.
+ ///
+ /// This function returns the arc with the given index.
+ /// \sa index()
+ Arc arc(int ix) const { return Parent::arcFromId(ix); }
+
+ /// \brief The index of the given node.
+ ///
+ /// This function returns the index of the the given node.
+ /// \sa node()
+ int index(Node node) const { return Parent::id(node); }
+
+ /// \brief The index of the given arc.
+ ///
+ /// This function returns the index of the the given arc.
+ /// \sa arc()
+ int index(Arc arc) const { return Parent::id(arc); }
+
+ /// \brief Number of nodes.
+ ///
+ /// This function returns the number of nodes.
+ int nodeNum() const { return node_num; }
+
+ /// \brief Number of arcs.
+ ///
+ /// This function returns the number of arcs.
+ int arcNum() const { return arc_num; }
+
/// \brief Build the digraph copying another digraph.
///
/// This function builds the digraph copying another digraph of any
@@ -288,6 +328,12 @@
Parent::build(digraph, nodeRef, arcRef);
}
+ /// \brief Clear the digraph.
+ ///
+ /// This function erases all nodes and arcs from the digraph.
+ void clear() {
+ Parent::clear();
+ }
protected:
diff --git a/test/digraph_test.cc b/test/digraph_test.cc
--- a/test/digraph_test.cc
+++ b/test/digraph_test.cc
@@ -445,6 +445,11 @@
checkArcIds(G);
checkGraphNodeMap(G);
checkGraphArcMap(G);
+
+ int n = G.nodeNum();
+ int m = G.arcNum();
+ check(G.index(G.node(n-1)) == n-1, "Wrong index.");
+ check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
}
void checkFullDigraph(int num) {
More information about the Lemon-commits
mailing list