src/hugo/list_graph.h
changeset 716 e7f13f60fcfd
parent 710 891f99700ea1
child 722 be8712e1fe07
equal deleted inserted replaced
7:a123d9f792f7 8:c268ae843e0f
   135     Node aNode(InEdgeIt e) const { return edges[e.n].head; }
   135     Node aNode(InEdgeIt e) const { return edges[e.n].head; }
   136 
   136 
   137     Node bNode(OutEdgeIt e) const { return edges[e.n].head; }
   137     Node bNode(OutEdgeIt e) const { return edges[e.n].head; }
   138     Node bNode(InEdgeIt e) const { return edges[e.n].tail; }
   138     Node bNode(InEdgeIt e) const { return edges[e.n].tail; }
   139 
   139 
   140     static NodeIt& first(NodeIt& v) const { 
   140     NodeIt& first(NodeIt& v) const { 
   141       v=NodeIt(*this); return v; }
   141       v=NodeIt(*this); return v; }
   142     static EdgeIt& first(EdgeIt& e) const { 
   142     EdgeIt& first(EdgeIt& e) const { 
   143       e=EdgeIt(*this); return e; }
   143       e=EdgeIt(*this); return e; }
   144     static OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
   144     OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
   145       e=OutEdgeIt(*this,v); return e; }
   145       e=OutEdgeIt(*this,v); return e; }
   146     static InEdgeIt& first(InEdgeIt& e, const Node v) const { 
   146     InEdgeIt& first(InEdgeIt& e, const Node v) const { 
   147       e=InEdgeIt(*this,v); return e; }
   147       e=InEdgeIt(*this,v); return e; }
   148 
   148 
   149 //     template< typename It >
   149 //     template< typename It >
   150 //     It first() const { It e; first(e); return e; }
   150 //     It first() const { It e; first(e); return e; }
   151 
   151 
   152 //     template< typename It >
   152 //     template< typename It >
   153 //     It first(Node v) const { It e; first(e,v); return e; }
   153 //     It first(Node v) const { It e; first(e,v); return e; }
   154 
   154 
   155     static bool valid(Edge e) const { return e.n!=-1; }
   155     static bool valid(Edge e) { return e.n!=-1; }
   156     static bool valid(Node n) const { return n.n!=-1; }
   156     static bool valid(Node n) { return n.n!=-1; }
   157     
   157     
   158     static void setInvalid(Edge &e) { e.n=-1; }
   158     static void setInvalid(Edge &e) { e.n=-1; }
   159     static void setInvalid(Node &n) { n.n=-1; }
   159     static void setInvalid(Node &n) { n.n=-1; }
   160     
   160     
   161     template <typename It> static It getNext(It it) const
   161     template <typename It> static It getNext(It it)
   162     { It tmp(it); return next(tmp); }
   162     { It tmp(it); return next(tmp); }
   163 
   163 
   164     NodeIt& next(NodeIt& it) const { 
   164     NodeIt& next(NodeIt& it) const { 
   165       it.n=nodes[it.n].next; 
   165       it.n=nodes[it.n].next; 
   166       return it; 
   166       return it; 
   181 	it.n = (n==-1)?-1:nodes[n].first_in;
   181 	it.n = (n==-1)?-1:nodes[n].first_in;
   182       }
   182       }
   183       return it;
   183       return it;
   184     }
   184     }
   185 
   185 
   186     static int id(Node v) const { return v.n; }
   186     static int id(Node v) { return v.n; }
   187     static int id(Edge e) const { return e.n; }
   187     static int id(Edge e) { return e.n; }
   188 
   188 
   189     /// Adds a new node to the graph.
   189     /// Adds a new node to the graph.
   190 
   190 
   191     /// \todo It adds the nodes in a reversed order.
   191     /// \todo It adds the nodes in a reversed order.
   192     /// (i.e. the lastly added node becomes the first.)
   192     /// (i.e. the lastly added node becomes the first.)
   625     void erase(Node n) { ListGraph::erase(n); }
   625     void erase(Node n) { ListGraph::erase(n); }
   626     ///The oppositely directed edge.
   626     ///The oppositely directed edge.
   627 
   627 
   628     ///Returns the oppositely directed
   628     ///Returns the oppositely directed
   629     ///pair of the edge \c e.
   629     ///pair of the edge \c e.
   630     static Edge opposite(Edge e) const
   630     static Edge opposite(Edge e)
   631     {
   631     {
   632       Edge f;
   632       Edge f;
   633       f.idref() = e.idref() - 2*(e.idref()%2) + 1;
   633       f.idref() = e.idref() - 2*(e.idref()%2) + 1;
   634       return f;
   634       return f;
   635     }
   635     }