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