src/work/alpar/list_graph.h
changeset 504 6ef30329dd50
parent 491 4804c967543d
child 508 95f8f7171bae
equal deleted inserted replaced
8:71f0138dc4f2 9:1048f3dd5647
   314       int n;
   314       int n;
   315       friend int ListGraph::id(Node v) const; 
   315       friend int ListGraph::id(Node v) const; 
   316       Node(int nn) {n=nn;}
   316       Node(int nn) {n=nn;}
   317     public:
   317     public:
   318       Node() {}
   318       Node() {}
   319       Node (Invalid i) { n=-1; }
   319       Node (Invalid) { n=-1; }
   320       bool operator==(const Node i) const {return n==i.n;}
   320       bool operator==(const Node i) const {return n==i.n;}
   321       bool operator!=(const Node i) const {return n!=i.n;}
   321       bool operator!=(const Node i) const {return n!=i.n;}
   322       bool operator<(const Node i) const {return n<i.n;}
   322       bool operator<(const Node i) const {return n<i.n;}
   323     };
   323     };
   324     
   324     
   501 	G->dyn_edge_maps.push_back(this);
   501 	G->dyn_edge_maps.push_back(this);
   502       } 
   502       } 
   503       EdgeMap(const EdgeMap<T> &m) :
   503       EdgeMap(const EdgeMap<T> &m) :
   504  	DynMapBase<Edge>(*m.G), container(m.container)
   504  	DynMapBase<Edge>(*m.G), container(m.container)
   505       {
   505       {
   506  	G->dyn_node_maps.push_back(this);
   506  	G->dyn_edge_maps.push_back(this);
   507       }
   507       }
   508 
   508 
   509       template<typename TT> friend class EdgeMap;
   509       template<typename TT> friend class EdgeMap;
   510 
   510 
   511       ///\todo It can copy between different types.
   511       ///\todo It can copy between different types.
   512       ///
   512       ///
   513       template<typename TT> EdgeMap(const EdgeMap<TT> &m) :
   513       template<typename TT> EdgeMap(const EdgeMap<TT> &m) :
   514 	DynMapBase<Edge>(*m.G)
   514 	DynMapBase<Edge>(*m.G)
   515       {
   515       {
   516 	G->dyn_node_maps.push_back(this);
   516 	G->dyn_edge_maps.push_back(this);
   517 	typename std::vector<TT>::const_iterator i;
   517 	typename std::vector<TT>::const_iterator i;
   518 	for(typename std::vector<TT>::const_iterator i=m.container.begin();
   518 	for(typename std::vector<TT>::const_iterator i=m.container.begin();
   519 	    i!=m.container.end();
   519 	    i!=m.container.end();
   520 	    i++)
   520 	    i++)
   521 	  container.push_back(*i);
   521 	  container.push_back(*i);
  1292     EdgeIt& next(EdgeIt& it) const {
  1292     EdgeIt& next(EdgeIt& it) const {
  1293       if(edges[it.n].next_in!=-1) { 
  1293       if(edges[it.n].next_in!=-1) { 
  1294 	it.n=edges[it.n].next_in;
  1294 	it.n=edges[it.n].next_in;
  1295       }
  1295       }
  1296       else {
  1296       else {
  1297 	typename NodeGraphType::Node n;
  1297 	NodeIt n;
  1298 	for(n=G.next(edges[it.n].head);
  1298 	for(n=next(edges[it.n].head);
  1299 	    G.valid(n) && nodes[n].first_in == -1;
  1299 	    valid(n) && nodes[n].first_in == -1;
  1300 	    G.next(n)) ;
  1300 	    next(n)) ;
  1301 	it.n = (G.valid(n))?-1:nodes[n].first_in;
  1301 	it.n = (valid(n))?-1:nodes[n].first_in;
  1302       }
  1302       }
  1303       return it;
  1303       return it;
  1304     }
  1304     }
  1305 
  1305 
  1306     int id(Node v) const { return G.id(v); }
  1306     int id(Node v) const { return G.id(v); }
  1383 //     void clear() {
  1383 //     void clear() {
  1384 //       nodes.clear();edges.clear();
  1384 //       nodes.clear();edges.clear();
  1385 //       first_node=first_free_node=first_free_edge=-1;
  1385 //       first_node=first_free_node=first_free_edge=-1;
  1386 //     }
  1386 //     }
  1387 
  1387 
       
  1388   public:
  1388     class Node : public NodeGraphType::Node {
  1389     class Node : public NodeGraphType::Node {
  1389       friend class EdgeSet;
  1390       friend class EdgeSet;
  1390       //      template <typename T> friend class NodeMap;
  1391       //      template <typename T> friend class NodeMap;
  1391       
  1392       
  1392       friend class Edge;
  1393       friend class Edge;
  1442     
  1443     
  1443     class EdgeIt : public Edge {
  1444     class EdgeIt : public Edge {
  1444       friend class EdgeSet;
  1445       friend class EdgeSet;
  1445     public:
  1446     public:
  1446       EdgeIt(const EdgeSet& G) : Edge() {
  1447       EdgeIt(const EdgeSet& G) : Edge() {
  1447       	typename NodeGraphType::Node m;
  1448 	//      	typename NodeGraphType::Node m;
       
  1449         NodeIt m;
  1448 	for(G.first(m);
  1450 	for(G.first(m);
  1449 	    G.valid(m) && nodes[m].first_in == -1;  G.next[m]);
  1451 	    G.valid(m) && G.nodes[m].first_in == -1;  G.next(m));
  1450 	n = G.valid(m)?-1:nodes[m].first_in;
  1452 	n = G.valid(m)?-1:G.nodes[m].first_in;
  1451       }
  1453       }
  1452       EdgeIt (Invalid i) : Edge(i) { }
  1454       EdgeIt (Invalid i) : Edge(i) { }
  1453       EdgeIt() : Edge() { }
  1455       EdgeIt() : Edge() { }
  1454       ///\bug This is a workaround until somebody tells me how to
  1456       ///\bug This is a workaround until somebody tells me how to
  1455       ///make class \c SymEdgeSet::SymEdgeMap friend of Edge
  1457       ///make class \c SymEdgeSet::SymEdgeMap friend of Edge
  1512 	G->dyn_edge_maps.push_back(this);
  1514 	G->dyn_edge_maps.push_back(this);
  1513       } 
  1515       } 
  1514       EdgeMap(const EdgeMap<T> &m) :
  1516       EdgeMap(const EdgeMap<T> &m) :
  1515  	DynMapBase<Edge>(*m.G), container(m.container)
  1517  	DynMapBase<Edge>(*m.G), container(m.container)
  1516       {
  1518       {
  1517  	G->dyn_node_maps.push_back(this);
  1519  	G->dyn_edge_maps.push_back(this);
  1518       }
  1520       }
  1519 
  1521 
  1520       template<typename TT> friend class EdgeMap;
  1522       template<typename TT> friend class EdgeMap;
  1521 
  1523 
  1522       ///\todo It can copy between different types.
  1524       ///\todo It can copy between different types.
  1523       ///
  1525       ///
  1524       template<typename TT> EdgeMap(const EdgeMap<TT> &m) :
  1526       template<typename TT> EdgeMap(const EdgeMap<TT> &m) :
  1525 	DynMapBase<Edge>(*m.G)
  1527 	DynMapBase<Edge>(*m.G)
  1526       {
  1528       {
  1527 	G->dyn_node_maps.push_back(this);
  1529 	G->dyn_edge_maps.push_back(this);
  1528 	typename std::vector<TT>::const_iterator i;
  1530 	typename std::vector<TT>::const_iterator i;
  1529 	for(typename std::vector<TT>::const_iterator i=m.container.begin();
  1531 	for(typename std::vector<TT>::const_iterator i=m.container.begin();
  1530 	    i!=m.container.end();
  1532 	    i!=m.container.end();
  1531 	    i++)
  1533 	    i++)
  1532 	  container.push_back(*i);
  1534 	  container.push_back(*i);