shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/ssi_igraph.hpp
Go to the documentation of this file.
00001 #ifndef ID_GRAPH_H
00002 #define ID_GRAPH_H
00003 #include <vector>
00004 #include <set>
00005 #include <list>
00006 #include <map>
00007 #include <iostream>
00008 struct igraph
00009 {
00010   typedef std::set<unsigned>     nset_t;
00011   typedef std::vector<nset_t>  graph_t;
00012   typedef nset_t::iterator  l_iterator; 
00013   typedef graph_t::iterator n_iterator;
00014   
00015   graph_t nodes;
00016   
00017   unsigned add_node()
00018   { nodes.push_back( nset_t() ) ;
00019     return nodes.size() - 1; };
00020   
00021   void add_link( unsigned a, unsigned b )
00022   {  nodes[a].insert( b ); };
00023 
00024   nset_t& operator[]( unsigned i ) 
00025   { return nodes[i]; };
00026   
00027   const 
00028   nset_t& operator[]( unsigned i ) const 
00029   { return nodes[i]; };
00030   
00031   bool neighbors( unsigned a, unsigned b )
00032   {
00033     return (nodes[a].find(b) != nodes[a].end()) || (nodes[b].find(a) != nodes[b].end());
00034   };
00035   void dump( std::ostream& o )
00036     {
00037       for ( unsigned i = 0; i < nodes.size(); i++ )
00038                 {
00039           o << i << " :\n";
00040           for ( nset_t::iterator it = nodes[i].begin(); it != nodes[i].end(); it++ )
00041             o << *it << " ";
00042           o << "\n";
00043         };
00044    };
00045 };
00046 
00047 
00048 
00049 #endif