marci_list_graph.hh in the new upper-cased concept
authormarci
Fri, 30 Jan 2004 14:52:04 +0000
changeset 460f1aacd7867b
parent 45 8fe92d6829e8
child 47 cbdb54e46d96
marci_list_graph.hh in the new upper-cased concept
src/work/list_graph.hh
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/list_graph.hh	Fri Jan 30 14:52:04 2004 +0000
     1.3 @@ -0,0 +1,552 @@
     1.4 +#ifndef MARCI_LIST_GRAPH_HH
     1.5 +#define MARCI_LIST_GRAPH_HH
     1.6 +
     1.7 +#include <iostream>
     1.8 +
     1.9 +namespace marci {
    1.10 +
    1.11 +  template <typename It>
    1.12 +  int number_of(It _it) { 
    1.13 +    int i=0;
    1.14 +    for( ; _it.valid(); ++_it) { ++i; } 
    1.15 +    return i;
    1.16 +  }
    1.17 +
    1.18 +  template <typename It>
    1.19 +  int count(It it) { 
    1.20 +    int i=0;
    1.21 +    for( ; it.valid(); ++it) { ++i; } 
    1.22 +    return i;
    1.23 +  }
    1.24 +
    1.25 +  class ListGraph {
    1.26 +    class node_item;
    1.27 +    class edge_item;
    1.28 +  public:
    1.29 +    class NodeIt;
    1.30 +    class EachNodeIt;
    1.31 +    class EdgeIt;
    1.32 +    class EachEdgeIt;
    1.33 +    class OutEdgeIt;
    1.34 +    class InEdgeIt;
    1.35 +    class SymEdgeIt;
    1.36 +
    1.37 +    template <typename T>
    1.38 +    class NodeMap {
    1.39 +      //typedef typename Graph::NodeIt NodeIt;
    1.40 +      //typedef typename Graph::EachNodeIt EachNodeIt;
    1.41 +      const ListGraph& G; 
    1.42 +      std::vector<T> container;
    1.43 +    public:
    1.44 +      NodeMap(const ListGraph& _G) : G(_G) {
    1.45 +	int i=0;
    1.46 +	for(EachNodeIt it=G.template first<EachNodeIt>(); it.valid(); ++it) ++i;
    1.47 +	container.resize(i); 
    1.48 +      }
    1.49 +      NodeMap(const ListGraph& _G, const T a) : G(_G) {
    1.50 +	for(EachNodeIt it=G.template first<EachNodeIt>(); it.valid(); ++it) { 
    1.51 +	  container.push_back(a); 
    1.52 +	}
    1.53 +      }
    1.54 +      void set(const NodeIt nit, const T a) { container[G.id(nit)]=a; }
    1.55 +      T get(const NodeIt nit) const { return container[G.id(nit)]; }
    1.56 +    };
    1.57 +
    1.58 +    template <typename T>
    1.59 +    class EdgeMap {
    1.60 +      //typedef typename Graph::EdgeIt EdgeIt;
    1.61 +      //typedef typename Graph::EachEdgeIt EachEdgeIt;
    1.62 +      const ListGraph& G; 
    1.63 +      std::vector<T> container;
    1.64 +    public:
    1.65 +      EdgeMap(const ListGraph& _G) : G(_G) {
    1.66 +	int i=0;
    1.67 +	for(EachEdgeIt it=G.template first<EachEdgeIt>(); it.valid(); ++it) ++i;
    1.68 +	container.resize(i); 
    1.69 +      }
    1.70 +      EdgeMap(const ListGraph& _G, const T a) : G(_G) {
    1.71 +	for(EachEdgeIt it=G.template first<EachEdgeIt>(); it.valid(); ++it) { 
    1.72 +	  container.push_back(a); 
    1.73 +	}
    1.74 +      }
    1.75 +      void set(const EdgeIt eit, const T a) { container[G.id(eit)]=a; }
    1.76 +      T get(const EdgeIt eit) const { return container[G.id(eit)]; }
    1.77 +    };
    1.78 +
    1.79 +    //typedef template<typename T> NodePropertyVector<ListGraph, T> NodeMap;
    1.80 +    //template <typename T>
    1.81 +    //typedef NodePropertyVector<ListGraph, T> NodeMap;
    1.82 +    //template <typename T>
    1.83 +    //typedef typename NodePropertyVector<ListGraph, T> NodeMap;
    1.84 +    //template <typename T>
    1.85 +    //typedef NodePropertyVector<typename ListGraph, T> NodeMap;
    1.86 +    //template <typename T>
    1.87 +    //typedef typename NodePropertyVector<typename ListGraph, T> NodeMap;
    1.88 +    //template <typename T>
    1.89 +    //typedef template NodePropertyVector<ListGraph, T> NodeMap;
    1.90 +    //template <typename T>
    1.91 +    //typedef template typename NodePropertyVector<ListGraph, T> NodeMap;
    1.92 +    //template <typename T>
    1.93 +    //typedef template NodePropertyVector<typename ListGraph, T> NodeMap;
    1.94 +    //template <typename T>
    1.95 +    //typedef template typename NodePropertyVector<typename ListGraph, T> NodeMap;
    1.96 +    //template <typename T>
    1.97 +    //typedef EdgePropertyVector<ListGraph, T> EdgeMap;
    1.98 +
    1.99 +  private:
   1.100 +    int node_id;
   1.101 +    int edge_id;
   1.102 +    int _node_num;
   1.103 +    int _edge_num;
   1.104 +
   1.105 +    node_item* _first_node;
   1.106 +    node_item* _last_node;
   1.107 +
   1.108 +    class node_item {
   1.109 +      friend class ListGraph;
   1.110 +      friend class NodeIt;
   1.111 +      friend class EachNodeIt;
   1.112 +      friend class EdgeIt;
   1.113 +      friend class EachEdgeIt;
   1.114 +      friend class OutEdgeIt;
   1.115 +      friend class InEdgeIt;
   1.116 +      friend class SymEdgeIt;
   1.117 +      friend std::ostream& operator<<(std::ostream& os, const NodeIt& i);
   1.118 +      friend std::ostream& operator<<(std::ostream& os, const EdgeIt& i);
   1.119 +      ListGraph* G;
   1.120 +      int id;
   1.121 +      edge_item* _first_out_edge;
   1.122 +      edge_item* _last_out_edge;
   1.123 +      edge_item* _first_in_edge;
   1.124 +      edge_item* _last_in_edge;
   1.125 +      node_item* _next_node;
   1.126 +      node_item* _prev_node;
   1.127 +    public:
   1.128 +      node_item() { }
   1.129 +    };
   1.130 +
   1.131 +    class edge_item {
   1.132 +      friend class ListGraph;
   1.133 +      friend class NodeIt;
   1.134 +      friend class EachNodeIt;
   1.135 +      friend class EdgeIt;
   1.136 +      friend class EachEdgeIt;
   1.137 +      friend class OutEdgeIt;
   1.138 +      friend class InEdgeIt;
   1.139 +      friend class SymEdgeIt;
   1.140 +      friend std::ostream& operator<<(std::ostream& os, const EdgeIt& i);
   1.141 +      ListGraph* G;
   1.142 +      int id;
   1.143 +      node_item* _tail;
   1.144 +      node_item* _head;
   1.145 +      edge_item* _next_out;
   1.146 +      edge_item* _prev_out;
   1.147 +      edge_item* _next_in;
   1.148 +      edge_item* _prev_in;
   1.149 +    public:
   1.150 +      edge_item() { }
   1.151 +    };
   1.152 +
   1.153 +    node_item* _add_node() { 
   1.154 +      node_item* p=new node_item;
   1.155 +      p->id=node_id++;
   1.156 +      p->_first_out_edge=0;
   1.157 +      p->_last_out_edge=0;
   1.158 +      p->_first_in_edge=0;
   1.159 +      p->_last_in_edge=0;
   1.160 +      p->_prev_node=_last_node;
   1.161 +      p->_next_node=0;
   1.162 +      if (_last_node) _last_node->_next_node=p;
   1.163 +      _last_node=p;
   1.164 +      if (!_first_node) _first_node=p;
   1.165 +
   1.166 +      ++_node_num;
   1.167 +      return p;
   1.168 +    }
   1.169 +
   1.170 +    edge_item* _add_edge(node_item* _tail, node_item* _head) {
   1.171 +      edge_item* e=new edge_item;
   1.172 +      e->id=edge_id++;
   1.173 +      e->_tail=_tail;
   1.174 +      e->_head=_head;
   1.175 +      
   1.176 +      e->_prev_out=_tail->_last_out_edge;
   1.177 +      if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;
   1.178 +      _tail->_last_out_edge=e;
   1.179 +      if (!_tail->_first_out_edge) _tail->_first_out_edge=e; 
   1.180 +      e->_next_out=0;
   1.181 + 
   1.182 +      e->_prev_in=_head->_last_in_edge;
   1.183 +      if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;
   1.184 +      _head->_last_in_edge=e;
   1.185 +      if (!_head->_first_in_edge) { _head->_first_in_edge=e; } 
   1.186 +      e->_next_in=0;
   1.187 +
   1.188 +      ++_edge_num;
   1.189 +      return e;
   1.190 +    }
   1.191 +
   1.192 +    //deletes a node which has no out edge and no in edge
   1.193 +    void _delete_node(node_item* v) {
   1.194 +      if (v->_next_node) (v->_next_node)->_prev_node=v->_prev_node; else 
   1.195 +	_last_node=v->_prev_node;
   1.196 +      if (v->_prev_node) (v->_prev_node)->_next_node=v->_next_node; else 
   1.197 +	_first_node=v->_next_node;
   1.198 +
   1.199 +      delete v;
   1.200 +      --_node_num;
   1.201 +    }
   1.202 +
   1.203 +    void _delete_edge(edge_item* e) {
   1.204 +      if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 
   1.205 +	(e->_tail)->_last_out_edge=e->_prev_out;
   1.206 +      if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 
   1.207 +	(e->_tail)->_first_out_edge=e->_next_out;
   1.208 +      if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 
   1.209 +	(e->_head)->_last_in_edge=e->_prev_in;
   1.210 +      if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 
   1.211 +	(e->_head)->_first_in_edge=e->_next_in;
   1.212 +
   1.213 +      delete e;
   1.214 +      --_edge_num;
   1.215 +    }
   1.216 +
   1.217 +    void _set_tail(edge_item* e, node_item* _tail) {
   1.218 +      if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 
   1.219 +	(e->_tail)->_last_out_edge=e->_prev_out;
   1.220 +      if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 
   1.221 +	(e->_tail)->_first_out_edge=e->_next_out;
   1.222 +      
   1.223 +      e->_tail=_tail;
   1.224 +      
   1.225 +      e->_prev_out=_tail->_last_out_edge;
   1.226 +      if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;
   1.227 +      _tail->_last_out_edge=e;
   1.228 +      if (!_tail->_first_out_edge) _tail->_first_out_edge=e; 
   1.229 +      e->_next_out=0;
   1.230 +    }
   1.231 +
   1.232 +    void _set_head(edge_item* e, node_item* _head) {
   1.233 +      if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 
   1.234 +	(e->_head)->_last_in_edge=e->_prev_in;
   1.235 +      if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 
   1.236 +	(e->_head)->_first_in_edge=e->_next_in;
   1.237 +      
   1.238 +      e->_head=_head;
   1.239 +      
   1.240 +      e->_prev_in=_head->_last_in_edge;
   1.241 +      if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;
   1.242 +      _head->_last_in_edge=e;
   1.243 +      if (!_head->_first_in_edge) { _head->_first_in_edge=e; } 
   1.244 +      e->_next_in=0;
   1.245 +    }
   1.246 +
   1.247 +  public:
   1.248 +
   1.249 +    /* default constructor */
   1.250 +
   1.251 +    ListGraph() : node_id(0), edge_id(0), _node_num(0), _edge_num(0), _first_node(0), _last_node(0) { }
   1.252 +    
   1.253 +    ~ListGraph() { 
   1.254 +      while (first<EachNodeIt>().valid()) deleteNode(first<EachNodeIt>());
   1.255 +    }
   1.256 +
   1.257 +    int nodeNum() const { return _node_num; }
   1.258 +    int edgeNum() const { return _edge_num; }
   1.259 +
   1.260 +    /* functions to construct iterators from the graph, or from each other */
   1.261 +
   1.262 +    EachNodeIt firstNode() const { return EachNodeIt(_first_node); }
   1.263 +    EachEdgeIt firstEdge() const { 
   1.264 +      node_item* v=_first_node;
   1.265 +      edge_item* edge=v->_first_out_edge;
   1.266 +      while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
   1.267 +      return EachEdgeIt(v, edge); 
   1.268 +    }
   1.269 +    
   1.270 +    //OutEdgeIt firstOutEdge(const NodeIt v) const { return OutEdgeIt(v); }
   1.271 +    InEdgeIt firstInEdge(const NodeIt v) const { return InEdgeIt(v); }
   1.272 +    SymEdgeIt firstSymEdge(const NodeIt v) const { return SymEdgeIt(v); }
   1.273 +    NodeIt tail(const EdgeIt e) const { return e.tailNode(); }
   1.274 +    NodeIt head(const EdgeIt e) const { return e.headNode(); }
   1.275 +
   1.276 +    NodeIt aNode(const OutEdgeIt& e) const { return e.aNode(); }
   1.277 +    NodeIt aNode(const InEdgeIt& e) const { return e.aNode(); }
   1.278 +    NodeIt aNode(const SymEdgeIt& e) const { return e.aNode(); }
   1.279 +
   1.280 +    NodeIt bNode(const OutEdgeIt& e) const { return e.bNode(); }
   1.281 +    NodeIt bNode(const InEdgeIt& e) const { return e.bNode(); }
   1.282 +    NodeIt bNode(const SymEdgeIt& e) const { return e.bNode(); }
   1.283 +
   1.284 +    //NodeIt invalid_node() { return NodeIt(); }
   1.285 +    //EdgeIt invalid_edge() { return EdgeIt(); }
   1.286 +    //OutEdgeIt invalid_out_edge() { return OutEdgeIt(); }
   1.287 +    //InEdgeIt invalid_in_edge() { return InEdgeIt(); }
   1.288 +    //SymEdgeIt invalid_sym_edge() { return SymEdgeIt(); }
   1.289 +
   1.290 +    /* same methods in other style */
   1.291 +    /* for experimental purpose */
   1.292 +
   1.293 +    void getFirst(EachNodeIt& v) const { v=EachNodeIt(_first_node); }
   1.294 +    void getFirst(EachEdgeIt& e) const { e=firstEdge(); }
   1.295 +    void getFirst(OutEdgeIt& e, const NodeIt& v) const { e=OutEdgeIt(v); }
   1.296 +    void getFirst(InEdgeIt& e, const NodeIt& v) const { e=InEdgeIt(v); }
   1.297 +    void getFirst(SymEdgeIt& e, const NodeIt& v) const { e=SymEdgeIt(v); }
   1.298 +    void getTail(NodeIt& n, const EdgeIt& e) const { n=tail(e); }
   1.299 +    void getHead(NodeIt& n, const EdgeIt& e) const { n=head(e); }
   1.300 +
   1.301 +    void getANode(NodeIt& n, const OutEdgeIt& e) const { n=e.aNode(); }
   1.302 +    void getANode(NodeIt& n, const InEdgeIt& e) const { n=e.aNode(); }
   1.303 +    void getANode(NodeIt& n, const SymEdgeIt& e) const { n=e.aNode(); }
   1.304 +    void getBNode(NodeIt& n, const OutEdgeIt& e) const { n=e.bNode(); }
   1.305 +    void getBNode(NodeIt& n, const InEdgeIt& e) const { n=e.bNode(); }
   1.306 +    void getBNode(NodeIt& n, const SymEdgeIt& e) const { n=e.bNode(); }
   1.307 +    //void get_invalid(NodeIt& n) { n=NodeIt(); }
   1.308 +    //void get_invalid(EdgeIt& e) { e=EdgeIt(); }
   1.309 +    //void get_invalid(OutEdgeIt& e) { e=OutEdgeIt(); }
   1.310 +    //void get_invalid(InEdgeIt& e) { e=InEdgeIt(); }
   1.311 +    //void get_invalid(SymEdgeIt& e) { e=SymEdgeIt(); }
   1.312 +
   1.313 +    template< typename It >
   1.314 +    It first() const { 
   1.315 +      It e;
   1.316 +      getFirst(e);
   1.317 +      return e; 
   1.318 +    }
   1.319 +
   1.320 +    template< typename It >
   1.321 +    It first(const NodeIt v) const { 
   1.322 +      It e;
   1.323 +      getFirst(e, v);
   1.324 +      return e; 
   1.325 +    }
   1.326 +
   1.327 +    /* for getting id's of graph objects */
   1.328 +    /* these are important for the implementation of property vectors */
   1.329 +
   1.330 +    int id(const NodeIt v) const { return v.node->id; }
   1.331 +    int id(const EdgeIt e) const { return e.edge->id; }
   1.332 +
   1.333 +    /* adding nodes and edges */
   1.334 +
   1.335 +    NodeIt addNode() { return NodeIt(_add_node()); }
   1.336 +    EdgeIt addEdge(const NodeIt u, const NodeIt v) {
   1.337 +      return EdgeIt(_add_edge(u.node, v.node)); 
   1.338 +    }
   1.339 +
   1.340 +    void deleteNode(const NodeIt i) { 
   1.341 +      while (first<OutEdgeIt>(i).valid()) deleteEdge(first<OutEdgeIt>(i));
   1.342 +      while (first<InEdgeIt>(i).valid()) deleteEdge(first<InEdgeIt>(i));
   1.343 +      _delete_node(i.node); 
   1.344 +    }
   1.345 +  
   1.346 +    void deleteEdge(const EdgeIt e) { _delete_edge(e.edge); }
   1.347 +
   1.348 +    void setTail(const EdgeIt e, const NodeIt tail) {
   1.349 +      _set_tail(e.edge, tail.node); 
   1.350 +    }
   1.351 +
   1.352 +    void setHead(const EdgeIt e, const NodeIt head) {
   1.353 +      _set_head(e.edge, head.node); 
   1.354 +    }
   1.355 +
   1.356 +    /* stream operations, for testing purpose */
   1.357 +
   1.358 +    friend std::ostream& operator<<(std::ostream& os, const NodeIt& i) { 
   1.359 +      os << i.node->id; return os; 
   1.360 +    }
   1.361 +    friend std::ostream& operator<<(std::ostream& os, const EdgeIt& i) { 
   1.362 +      os << "(" << i.edge->_tail->id << "--" << i.edge->id << "->" << i.edge->_head->id << ")"; 
   1.363 +      return os; 
   1.364 +    }
   1.365 +
   1.366 +    class NodeIt {
   1.367 +      friend class ListGraph;
   1.368 +
   1.369 +      friend class EdgeIt;
   1.370 +      friend class OutEdgeIt;
   1.371 +      friend class InEdgeIt;
   1.372 +      friend class SymEdgeIt;
   1.373 +    protected:
   1.374 +      node_item* node;
   1.375 +      friend int ListGraph::id(const NodeIt v) const; 
   1.376 +    public:
   1.377 +      NodeIt() : node(0) { }
   1.378 +      NodeIt(node_item* _node) : node(_node) { }
   1.379 +      bool valid() const { return (node!=0); }
   1.380 +      //void makeInvalid() { node=0; }
   1.381 +      friend bool operator==(const NodeIt& u, const NodeIt& v) { 
   1.382 +	return v.node==u.node; 
   1.383 +      } 
   1.384 +      friend bool operator!=(const NodeIt& u, const NodeIt& v) { 
   1.385 +	return v.node!=u.node; 
   1.386 +      } 
   1.387 +      friend std::ostream& operator<<(std::ostream& os, const NodeIt& i);
   1.388 +    };
   1.389 +    
   1.390 +    class EachNodeIt : public NodeIt {
   1.391 +      friend class ListGraph;
   1.392 +    public:
   1.393 +      EachNodeIt() : NodeIt() { }
   1.394 +      EachNodeIt(node_item* v) : NodeIt(v) { }
   1.395 +      EachNodeIt(const ListGraph& G) : NodeIt(G._first_node) { }
   1.396 +      EachNodeIt& operator++() { node=node->_next_node; return *this; }
   1.397 +    };
   1.398 +
   1.399 +    class EdgeIt {
   1.400 +      friend class ListGraph;
   1.401 +      
   1.402 +      friend class NodeIt;
   1.403 +      friend class EachNodeIt;
   1.404 +    protected:
   1.405 +      edge_item* edge;
   1.406 +      friend int ListGraph::id(const EdgeIt e) const;
   1.407 +    public:
   1.408 +      EdgeIt() : edge(0) { }
   1.409 +      //EdgeIt() { }
   1.410 +      EdgeIt(edge_item* _edge) : edge(_edge) { }
   1.411 +      bool valid() const { return (edge!=0); }
   1.412 +      //void makeInvalid() { edge=0; }
   1.413 +      friend bool operator==(const EdgeIt& u, const EdgeIt& v) { 
   1.414 +	return v.edge==u.edge; 
   1.415 +      } 
   1.416 +      friend bool operator!=(const EdgeIt& u, const EdgeIt& v) { 
   1.417 +	return v.edge!=u.edge; 
   1.418 +      } 
   1.419 +    protected:
   1.420 +      NodeIt tailNode() const { return NodeIt(edge->_tail); }
   1.421 +      NodeIt headNode() const { return NodeIt(edge->_head); }
   1.422 +    public:
   1.423 +      friend std::ostream& operator<<(std::ostream& os, const EdgeIt& i);
   1.424 +    };
   1.425 +    
   1.426 +    class EachEdgeIt : public EdgeIt {
   1.427 +      friend class ListGraph;
   1.428 +      node_item* v;
   1.429 +    public:
   1.430 +      EachEdgeIt() : EdgeIt(), v(0) { }
   1.431 +      EachEdgeIt(node_item* _v, edge_item* _e) : EdgeIt(_e), v(_v) { }
   1.432 +      EachEdgeIt(const ListGraph& G) {
   1.433 +	v=G._first_node;
   1.434 +	edge=v->_first_out_edge;
   1.435 +	while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
   1.436 +      }
   1.437 +      EachEdgeIt& operator++() { 
   1.438 +	edge=edge->_next_out; 
   1.439 +	while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
   1.440 +	return *this;
   1.441 +      }
   1.442 +    };
   1.443 +    
   1.444 +    class OutEdgeIt : public EdgeIt {
   1.445 +      friend class ListGraph;
   1.446 +      node_item* v;
   1.447 +    public:
   1.448 +      OutEdgeIt() : EdgeIt(), v(0) { }
   1.449 +    protected:
   1.450 +      OutEdgeIt(const NodeIt& _v) : v(_v.node) { edge=v->_first_out_edge; }
   1.451 +    public:
   1.452 +      OutEdgeIt(const ListGraph& G, const NodeIt _v) : v(_v.node) { edge=v->_first_out_edge; }
   1.453 +      OutEdgeIt& operator++() { edge=edge->_next_out; return *this; }
   1.454 +    protected:
   1.455 +      NodeIt aNode() const { return NodeIt(v); }
   1.456 +      NodeIt bNode() const { 
   1.457 +	return (edge->_tail==v) ? NodeIt(edge->_head) : NodeIt(edge->_tail); }
   1.458 +    };
   1.459 +    
   1.460 +    class InEdgeIt : public EdgeIt {
   1.461 +      friend class ListGraph;
   1.462 +      node_item* v;
   1.463 +    public:
   1.464 +      InEdgeIt() : EdgeIt(), v(0) { }
   1.465 +    protected:
   1.466 +      InEdgeIt(const NodeIt& _v) : v(_v.node) { 
   1.467 +	edge=v->_first_in_edge; 
   1.468 +      }
   1.469 +    public:
   1.470 +      InEdgeIt(const ListGraph& G, const NodeIt _v) : v(_v.node) { edge=v->_first_in_edge; }
   1.471 +      InEdgeIt& operator++() { edge=edge->_next_in; return *this; }
   1.472 +    protected:
   1.473 +      NodeIt aNode() const { return NodeIt(v); }
   1.474 +      NodeIt bNode() const { 
   1.475 +	return (edge->_tail==v) ? NodeIt(edge->_head) : NodeIt(edge->_tail); }
   1.476 +    };
   1.477 +
   1.478 +    class SymEdgeIt : public EdgeIt {
   1.479 +      friend class ListGraph;
   1.480 +      bool out_or_in; //1 iff out, 0 iff in
   1.481 +      node_item* v;
   1.482 +    public:
   1.483 +      SymEdgeIt() : EdgeIt(), v(0) { }
   1.484 +    protected:
   1.485 +      SymEdgeIt(const NodeIt& _v) : v(_v.node) { 
   1.486 +	out_or_in=1;
   1.487 +	edge=v->_first_out_edge; 
   1.488 +	if (!edge) { edge=v->_first_in_edge; out_or_in=0; }
   1.489 +      }
   1.490 +    public:
   1.491 +      SymEdgeIt(const ListGraph& G, const NodeIt _v) : v(_v.node) { 
   1.492 +	out_or_in=1;
   1.493 +	edge=v->_first_out_edge; 
   1.494 +	if (!edge) { edge=v->_first_in_edge; out_or_in=0; }
   1.495 +      }
   1.496 +      SymEdgeIt& operator++() { 
   1.497 +	if (out_or_in) { 
   1.498 +	  edge=edge->_next_out; 
   1.499 +	  if (!edge) { out_or_in=0; edge=v->_first_in_edge; }
   1.500 +	} else {
   1.501 +	  edge=edge->_next_in; 
   1.502 +	}
   1.503 +	return *this;
   1.504 +      }
   1.505 +    protected:
   1.506 +      NodeIt aNode() const { return NodeIt(v); }
   1.507 +      NodeIt bNode() const { 
   1.508 +	return (edge->_tail==v) ? NodeIt(edge->_head) : NodeIt(edge->_tail); }
   1.509 +    };
   1.510 +
   1.511 +  };
   1.512 +
   1.513 +  /*
   1.514 +  template< typename T >
   1.515 +  T ListGraph::first() const { 
   1.516 +    std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>();" << std::endl; 
   1.517 +    return T(); 
   1.518 +  }
   1.519 +
   1.520 +  template<>
   1.521 +  ListGraph::EachNodeIt ListGraph::first<ListGraph::EachNodeIt>() const { 
   1.522 +    return firstNode(); 
   1.523 +  }
   1.524 +
   1.525 +  template<>
   1.526 +  ListGraph::EachEdgeIt ListGraph::first<ListGraph::EachEdgeIt>() const { 
   1.527 +    return firstEdge(); 
   1.528 +  }
   1.529 +
   1.530 +  template< typename T >
   1.531 +  T ListGraph::first(ListGraph::NodeIt v) const {
   1.532 +    std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>(ListGRaph::NodeIt);" << std::endl; 
   1.533 +    return T(); 
   1.534 +  } 
   1.535 +
   1.536 +  template<>
   1.537 +  ListGraph::OutEdgeIt ListGraph::first<ListGraph::OutEdgeIt>(const ListGraph::NodeIt v) const { 
   1.538 +    return firstOutEdge(v); 
   1.539 +  }
   1.540 +
   1.541 +  template<>
   1.542 +  ListGraph::InEdgeIt ListGraph::first<ListGraph::InEdgeIt>(const ListGraph::NodeIt v) const { 
   1.543 +    return firstInEdge(v); 
   1.544 +  }
   1.545 +
   1.546 +  template<>
   1.547 +  ListGraph::SymEdgeIt ListGraph::first<ListGraph::SymEdgeIt>(const ListGraph::NodeIt v) const { 
   1.548 +    return firstSymEdge(v); 
   1.549 +  }
   1.550 +  */
   1.551 +
   1.552 +
   1.553 +} //namespace marci
   1.554 +
   1.555 +#endif //MARCI_LIST_GRAPH_HH