URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-25 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update Graph.
* graph.hh,
* graph.hxx,
* main.cc: Update.
---
graph.hh | 49 +++++++++++++++++++++++++++++++++++--------------
graph.hxx | 24 +++++++++++++-----------
main.cc | 8 +++++---
3 files changed, 53 insertions(+), 28 deletions(-)
Index: trunk/milena/sandbox/duhamel/graph.hh
===================================================================
--- trunk/milena/sandbox/duhamel/graph.hh (revision 1171)
+++ trunk/milena/sandbox/duhamel/graph.hh (revision 1172)
@@ -39,40 +39,61 @@
namespace util
{
- template<typename N, typename E = void>
- class Graph
+ template<typename T>
+ struct s_node
{
- public:
- typedef struct s_node
+ T data;
+ std::vector<unsigned> links;
+ };
+
+ template<>
+ struct s_node<void>
{
std::vector<unsigned> links;
- } s_node;
+ };
+
+ template<typename T>
+ struct s_edge
+ {
+ T data;
+ unsigned node1;
+ unsigned node2;
+ };
- typedef struct s_edge
+ template<>
+ struct s_edge <void>
{
unsigned node1;
unsigned node2;
- } s_edge;
+ };
- Graph () {}
+ template<typename N, typename E = void>
+ class Graph
+ {
+ public:
+ Graph () :
+ nb_node_ (0), nb_link_ (0) {}
Graph (unsigned nb_node, unsigned nb_link) :
nb_node_ (nb_node), nb_link_ (nb_link) {}
~Graph () {}
- void add_node ();
+
+ // void add_node (N& elt);
+ void add_node (void);
void add_edge (unsigned n1, unsigned n2);
- void coherce ();
- void print ();
-// void coherence () const;
+ void coherence () const;
+ void print_debug () const;
+
private:
unsigned nb_node_;
unsigned nb_link_;
- std::vector<s_node*> nodes_;
- std::vector<s_edge*> links_;
+ std::vector<struct s_node<N>*> nodes_;
+ std::vector<struct s_edge<E>*> links_;
};
} // end of util
} // end of mln
+
#include "graph.hxx"
#endif // MLN_GRAPH_HH
Index: trunk/milena/sandbox/duhamel/graph.hxx
===================================================================
--- trunk/milena/sandbox/duhamel/graph.hxx (revision 1171)
+++ trunk/milena/sandbox/duhamel/graph.hxx (revision 1172)
@@ -8,16 +8,18 @@
namespace util
{
-
template<typename N, typename E>
inline
void
- Graph<N, E>::add_node ()
+ Graph<N, E>::add_node (void)
{
- nodes_.push_back (new s_node);
+ struct s_node<N>* n = new struct s_node<N>;
+
+ nodes_.push_back (n);
++nb_node_;
}
+
template<typename N, typename E>
inline
void
@@ -26,9 +28,9 @@
mln_precondition(n1 < this->nb_node_);
mln_precondition(n2 < this->nb_node_);
- s_edge* edge;
+ struct s_edge<E>* edge;
- edge = new s_edge;
+ edge = new struct s_edge<E>;
edge->node1 = n1;
edge->node2 = n2;
links_.push_back (edge);
@@ -39,11 +41,11 @@
template<typename N, typename E>
inline
void
- Graph<N, E>::coherce ()
+ Graph<N, E>::coherence () const
{
mln_precondition(nodes_.size () == this->nb_node_);
mln_precondition(links_.size () == this->nb_link_);
- typename std::vector<s_node*>::const_iterator it = nodes_.begin ();
+ typename std::vector<struct s_node <N>*>::const_iterator it =
nodes_.begin ();
for (; it != nodes_.end (); ++it)
{
typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
@@ -51,7 +53,7 @@
mln_precondition((*it2) < nb_node_);
}
- typename std::vector<s_edge*>::const_iterator it3 = links_.begin ();
+ typename std::vector<struct s_edge<E>*>::const_iterator it3 =
links_.begin ();
for (; it3 != links_.end (); ++it3)
{
mln_precondition((*it3)->node1 < nb_node_);
@@ -62,12 +64,12 @@
template<typename N, typename E>
inline
void
- Graph<N, E>::print ()
+ Graph<N, E>::print_debug () const
{
std::cout << "nodes :"
<< std::endl;
- typename std::vector<s_node*>::const_iterator it = nodes_.begin ();
+ typename std::vector<struct s_node<N>*>::const_iterator it =
nodes_.begin ();
int i = 0;
for (; it != nodes_.end (); ++it, ++i)
{
@@ -75,7 +77,7 @@
<< i
<< " nbh : ";
typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
- for (; it2 != (*it)->links.end (); ++it2, ++i)
+ for (; it2 != (*it)->links.end (); ++it2)
{
std::cout << (*it2)
<< " ";
Index: trunk/milena/sandbox/duhamel/main.cc
===================================================================
--- trunk/milena/sandbox/duhamel/main.cc (revision 1171)
+++ trunk/milena/sandbox/duhamel/main.cc (revision 1172)
@@ -1,18 +1,20 @@
#include "graph.hh"
+//#include "mesh_p.hh"
+//#include "mesh_psite.hh"
using namespace mln;
int
main (void)
{
- mln::util::Graph<void> g (0,0);
+ util::Graph<void> g;
g.add_node ();
g.add_node ();
g.add_node ();
g.add_edge (0,1);
- g.coherce ();
- g.print ();
+ g.coherence ();
+ g.print_debug ();
// image2d_b<int> out (5, 5, 1);