src/work/alpar/smart_graph.h
changeset 183 ee62b0d90933
parent 174 44700ed9ffaa
child 185 259540358bbf
equal deleted inserted replaced
10:62469e587e28 11:024ce84a4fdb
     9 #include <invalid.h>
     9 #include <invalid.h>
    10 
    10 
    11 namespace hugo {
    11 namespace hugo {
    12 
    12 
    13   class SmartGraph {
    13   class SmartGraph {
    14 
       
    15 //     static const int INVALID=-1;
       
    16 //     static const int INVALID_NODE=INT_MAX;
       
    17 
    14 
    18     struct NodeT 
    15     struct NodeT 
    19     {
    16     {
    20       int first_in,first_out;      
    17       int first_in,first_out;      
    21       NodeT() : first_in(-1), first_out(-1) {}
    18       NodeT() : first_in(-1), first_out(-1) {}
   114       e=OutEdgeIt(*this,v); return e; }
   111       e=OutEdgeIt(*this,v); return e; }
   115     InEdgeIt& first(InEdgeIt& e, const Node v) const { 
   112     InEdgeIt& first(InEdgeIt& e, const Node v) const { 
   116       e=InEdgeIt(*this,v); return e; }
   113       e=InEdgeIt(*this,v); return e; }
   117 
   114 
   118     template< typename It >
   115     template< typename It >
   119     It first() const { 
   116     It first() const { It e; first(e); return e; }
   120       It e;
       
   121       //Marci
       
   122       /*getF*/first(e);
       
   123       return e; 
       
   124     }
       
   125 
   117 
   126     template< typename It >
   118     template< typename It >
   127     It first(Node v) const { 
   119     It first(Node v) const { It e; first(e,v); return e; }
   128       It e;
       
   129       //Marci
       
   130       /*getF*/first(e, v);
       
   131       return e; 
       
   132     }
       
   133 
   120 
   134     bool valid(Edge e) const { return e.n!=-1; }
   121     bool valid(Edge e) const { return e.n!=-1; }
   135     //    bool valid(EdgeIt e) const { return e.n<int(edges.size()); }
       
   136     bool valid(Node n) const { return n.n!=-1; }
   122     bool valid(Node n) const { return n.n!=-1; }
   137     
   123     
   138     void setInvalid(Edge &e) { e.n=-1; }
   124     void setInvalid(Edge &e) { e.n=-1; }
   139     void setInvalid(Node &n) { n.n=-1; }
   125     void setInvalid(Node &n) { n.n=-1; }
   140     
   126     
   141     template <typename It> It getNext(It it) const
   127     template <typename It> It getNext(It it) const
   142     { It tmp(it); return next(tmp); }
   128     { It tmp(it); return next(tmp); }
   143     //{ It tmp; tmp.n=it.n+1; return tmp; }
   129 
   144 
       
   145     //FIXME correction Marci: I changed to NodeIt from Node
       
   146     //NodeIt& next(NodeIt& it) const { it.n=(it.n+2)%nodes.size()-1; return it; }
       
   147     NodeIt& next(NodeIt& it) const { 
   130     NodeIt& next(NodeIt& it) const { 
   148       it.n=(it.n+2)%(nodes.size()+1)-1; 
   131       it.n=(it.n+2)%(nodes.size()+1)-1; 
   149       return it; 
   132       return it; 
   150     }
   133     }
   151     OutEdgeIt& next(OutEdgeIt& it) const
   134     OutEdgeIt& next(OutEdgeIt& it) const
   223       friend int SmartGraph::id(Edge e) const;
   206       friend int SmartGraph::id(Edge e) const;
   224 
   207 
   225       Edge(int nn) {n=nn;}
   208       Edge(int nn) {n=nn;}
   226     public:
   209     public:
   227       Edge() { }
   210       Edge() { }
   228       // Marci: kiszedtem az Invalid i-bol az i-t 
       
   229       Edge (Invalid) { n=-1; }
   211       Edge (Invalid) { n=-1; }
   230       bool operator==(const Edge i) const {return n==i.n;}
   212       bool operator==(const Edge i) const {return n==i.n;}
   231       bool operator!=(const Edge i) const {return n!=i.n;}
   213       bool operator!=(const Edge i) const {return n!=i.n;}
   232       bool operator<(const Edge i) const {return n<i.n;}
   214       bool operator<(const Edge i) const {return n<i.n;}
   233     };
   215     };
   328 
   310 
   329       void add(const Node k) 
   311       void add(const Node k) 
   330       {
   312       {
   331 	if(k.n>=container.size()) container.resize(k.n+1);
   313 	if(k.n>=container.size()) container.resize(k.n+1);
   332       }
   314       }
       
   315 
   333 //       void erase(const Node k)
   316 //       void erase(const Node k)
   334 //       {
   317 //       {
   335 // 	//FIXME: Please implement me.
   318 // 	//FIXME: Please implement me.
   336 //       }
   319 //       }
   337 //       void erase(const Edge k)
   320 //       void erase(const Edge k)