src/work/marci/graph_wrapper.h
changeset 246 dc95ca4ebc7b
parent 238 ad3bdd78f4f6
child 259 509ba9f136d2
equal deleted inserted replaced
16:1aee4374b56a 17:ffa1cee45b91
   538       Edge() : out_or_in(), out(), in() { }
   538       Edge() : out_or_in(), out(), in() { }
   539       Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
   539       Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
   540       operator GraphEdge() const {
   540       operator GraphEdge() const {
   541 	if (out_or_in) return(out); else return(in);
   541 	if (out_or_in) return(out); else return(in);
   542       }
   542       }
       
   543 //FIXME
       
   544 //2 edges are equal if they "refer" to the same physical edge 
       
   545 //is it good?
   543       friend bool operator==(const Edge& u, const Edge& v) { 
   546       friend bool operator==(const Edge& u, const Edge& v) { 
   544 	if (v.out_or_in) 
   547 	if (v.out_or_in) 
   545 	  return (u.out_or_in && u.out==v.out);
   548 	  if (u.out_or_in) return (u.out==v.out); else return (u.out==v.in);
       
   549 	//return (u.out_or_in && u.out==v.out);
   546 	else
   550 	else
   547 	  return (!u.out_or_in && u.in==v.in);
   551 	  if (u.out_or_in) return (u.out==v.in); else return (u.in==v.in);
       
   552 	//return (!u.out_or_in && u.in==v.in);
   548       } 
   553       } 
   549       friend bool operator!=(const Edge& u, const Edge& v) { 
   554       friend bool operator!=(const Edge& u, const Edge& v) { 
   550 	if (v.out_or_in) 
   555 	if (v.out_or_in) 
   551 	  return (!u.out_or_in || u.out!=v.out);
   556 	  if (u.out_or_in) return (u.out!=v.out); else return (u.out!=v.in);
       
   557 	//return (!u.out_or_in || u.out!=v.out);
   552 	else
   558 	else
   553 	  return (u.out_or_in || u.in!=v.in);
   559 	  if (u.out_or_in) return (u.out!=v.in); else return (u.in!=v.in);
       
   560 	//return (u.out_or_in || u.in!=v.in);
   554       } 
   561       } 
   555     };
   562     };
   556 
   563 
   557     class OutEdgeIt : public Edge {
   564     class OutEdgeIt : public Edge {
   558       friend class UndirGraphWrapper<GraphWrapper>;
   565       friend class UndirGraphWrapper<GraphWrapper>;
   559     public:
   566     public:
   560       OutEdgeIt() : Edge() { }
   567       OutEdgeIt() : Edge() { }
   561       OutEdgeIt(const Invalid& i) : Edge(i) { }
   568       OutEdgeIt(const Invalid& i) : Edge(i) { }
   562       OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) 
   569       OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) 
   563 	: Edge() { 
   570 	: Edge() { 
   564 	out_or_in=true;
   571 	out_or_in=true; _G.gw.first(out, n);
   565 	_G.gw.first(out, n);
   572 	if (!(_G.gw.valid(out))) { out_or_in=false; _G.gw.first(in, n);	}
   566 	if (!(_G.gw.valid(out))) {
       
   567 	  out_or_in=false;
       
   568 	  _G.gw.first(in, n);
       
   569 	}
       
   570       }
   573       }
   571     };
   574     };
   572 
   575 
   573     typedef OutEdgeIt InEdgeIt; 
   576     typedef OutEdgeIt InEdgeIt; 
   574 
   577 
   591 	}
   594 	}
   592       }
   595       }
   593     };
   596     };
   594 
   597 
   595     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
   598     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
   596       e.out_or_in=true;
   599       e.out_or_in=true; gw.first(e.out, n);
   597       gw.first(e.out, n);
   600       if (!(gw.valid(e.out))) { e.out_or_in=false; gw.first(e.in, n); }
   598       if (!(gw.valid(e.out))) {
       
   599 	e.out_or_in=false;
       
   600 	gw.first(e.in, n);
       
   601       }
       
   602       return e;
   601       return e;
   603     }
   602     }
   604 
   603 
   605     EdgeIt& first(EdgeIt& e) const {
   604     EdgeIt& first(EdgeIt& e) const {
   606       e.out_or_in=true;
   605       e.out_or_in=true;
   620 
   619 
   621     OutEdgeIt& next(OutEdgeIt& e) const {
   620     OutEdgeIt& next(OutEdgeIt& e) const {
   622       if (e.out_or_in) {
   621       if (e.out_or_in) {
   623 	Node n=gw.tail(e.out);
   622 	Node n=gw.tail(e.out);
   624 	gw.next(e.out);
   623 	gw.next(e.out);
   625 	if (!gw.valid(e.out)) {
   624 	if (!gw.valid(e.out)) { e.out_or_in=false; gw.first(e.in, n); }
   626 	  e.out_or_in=false;
       
   627 	  gw.first(e.in, n);
       
   628 	}
       
   629       } else {
   625       } else {
   630 	gw.next(e.in);
   626 	gw.next(e.in);
   631       }
   627       }
   632       return e;
   628       return e;
   633     }
   629     }
   641       }
   637       }
   642       return e;
   638       return e;
   643     }
   639     }
   644 
   640 
   645     template<typename I> I& next(I &i) const { return gw.next(i); }    
   641     template<typename I> I& next(I &i) const { return gw.next(i); }    
   646     
   642     template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
   647     template<typename I> I getNext(const I& i) const { 
       
   648       return gw.getNext(i); }
       
   649 
   643 
   650     template< typename It > It first() const { 
   644     template< typename It > It first() const { 
   651       It e; first(e); return e; }
   645       It e; first(e); return e; }
   652 
   646 
   653     template< typename It > It first(const Node& v) const { 
   647     template< typename It > It first(const Node& v) const {