src/include/graph.h
changeset 224 5bc1c83257f8
parent 8 cd54905012bc
equal deleted inserted replaced
4:f1a590440654 5:dc95c2b003d8
    16   {
    16   {
    17   public:
    17   public:
    18     typedef E EdgeType;
    18     typedef E EdgeType;
    19     typedef N NodeType;
    19     typedef N NodeType;
    20     
    20     
    21     class EdgePoint
    21     class EdgeIt
    22     {
    22     {
    23     public:
    23     public:
    24       NEGRO::EdgePoint e;
    24       NEGRO::EdgePoint e;
    25       bool isValid() { return e; }
    25       bool valid() { return e; }
    26     };
    26     };
    27     
    27     
    28     class InEdgePoint : public EdgePoint {};
    28     class InEdgeIt : public EdgeIt {};
    29     class OutEdgePoint : public EdgePoint {};
    29     class OutEdgeIt : public EdgeIt {};
    30     class BiEdgePoint : public EdgePoint {};
    30     class BiEdgeIt : public EdgeIt {};
    31     class SymEdgePoint : public EdgePoint {};
    31     class SymEdgeIt : public EdgeIt {};
    32     
    32     
    33     typedef int NodePoint;
    33     typedef int NodeIt;
       
    34     
       
    35     typedef NodeIt EachNodeIt;
    34     
    36     
    35     class NodeIterator;
    37     class NodeIterator;
    36     
    38     
    37     class EdgeIterator;
    39     class EdgeIterator;
    38     class InEdgeIterator;
    40     class InEdgeIterator;
    47     friend class EdgeIterator;
    49     friend class EdgeIterator;
    48     friend class InEdgeIterator;
    50     friend class InEdgeIterator;
    49     friend class OutEdgeIterator;
    51     friend class OutEdgeIterator;
    50     friend class BiEdgeIterator;
    52     friend class BiEdgeIterator;
    51     friend class SymEdgeIterator;
    53     friend class SymEdgeIterator;
    52     friend class AllEdgeIterator;
    54     friend class EachEdgeIterator;
    53     
    55     
    54     class NodeIterator
    56     class NodeIterator
    55     {
    57     {
    56       Graph<N,E> *G;  //operator*() miatt kell!!!
    58       Graph<N,E> *G;  //operator*() miatt kell!!!
    57       int n;     //nem kellene, ha itt mutato lenne!!
    59       int n;     //nem kellene, ha itt mutato lenne!!
    60       NodeIterator() {;} 
    62       NodeIterator() {;} 
    61       NodeIterator(Graph<N,E> &Gr)//'const Graph<N,E> &G' would be wrong.
    63       NodeIterator(Graph<N,E> &Gr)//'const Graph<N,E> &G' would be wrong.
    62       {G=&Gr;n=Gr.OldGraph<N,E>::FirstNode();} 
    64       {G=&Gr;n=Gr.OldGraph<N,E>::FirstNode();} 
    63       NodeIterator(const NodeIterator &i) {G=i.G;n=i.n;}
    65       NodeIterator(const NodeIterator &i) {G=i.G;n=i.n;}
    64       
    66       
    65       NodeIterator &GoNext() { n=G->NextNode(n); return *this;}
    67       NodeIterator &goNext() { n=G->NextNode(n); return *this;}
    66       NodeIterator Next() const { return NodeIterator(*this).GoNext();}
    68       NodeIterator next() const { return NodeIterator(*this).goNext();}
    67       NodeIterator &operator++() { return GoNext();} 
    69       NodeIterator &operator++() { return goNext();} 
    68       NodeIterator operator++(int)
    70       NodeIterator operator++(int)
    69       {NodeIterator tmp(*this); GoNext(); return tmp;}
    71       {NodeIterator tmp(*this); goNext(); return tmp;}
    70       bool isValid() { return n!=INVALID; }
    72       bool valid() { return n!=INVALID; }
    71       
    73       
    72       N &operator*() const { return G->Data(n); }
    74       N &operator*() const { return G->Data(n); }
    73       N *operator->() const { return &G->Data(n); }
    75       N *operator->() const { return &G->Data(n); }
    74       
    76       
    75       bool operator==(const NodeIterator &i) const {return n==i.n;}
    77       bool operator==(const NodeIterator &i) const {return n==i.n;}
    76       bool operator!=(const NodeIterator &i) const {return n!=i.n;}
    78       bool operator!=(const NodeIterator &i) const {return n!=i.n;}
    77       
    79       
    78       int Index() const { return n; } //If the nodes are indexable 
    80       int index() const { return n; } //If the nodes are indexable 
    79       friend class Graph;
    81       friend class Graph;
    80       friend class EdgeIterator;
    82       friend class EdgeIterator;
    81       friend class InEdgeIterator;
    83       friend class InEdgeIterator;
    82       friend class OutEdgeIterator;
    84       friend class OutEdgeIterator;
    83       friend class BiEdgeIterator;
    85       friend class BiEdgeIterator;
    84       friend class SymEdgeIterator;
    86       friend class SymEdgeIterator;
    85       friend class AllEdgeIterator;
    87       friend class EachEdgeIterator;
    86       friend class FirstAnythingTypeNode;
    88       friend class FirstAnythingTypeNode;
    87 
    89 
    88       //Nem kellene egy:
    90       //Nem kellene egy:
    89       //      static NodeIterator &GetInvalid();  ?
    91       //      static NodeIterator &GetInvalid();  ?
    90     };
    92     };
    94       
    96       
    95       Graph<N,E> *G; //Itt baj van!!!!! operator*() miatt kell!
    97       Graph<N,E> *G; //Itt baj van!!!!! operator*() miatt kell!
    96       //Ez csak kicsit baj, de:
    98       //Ez csak kicsit baj, de:
    97       // Meg a From() es To() miatt!!!!!!!!!!
    99       // Meg a From() es To() miatt!!!!!!!!!!
    98       
   100       
    99       NEGRO::EdgePoint e;
   101       NEGRO::EdgeIt e;
   100       
   102       
   101     public:
   103     public:
   102       EdgeIterator() {;} //Kell inicializalni? (Nem)
   104       EdgeIterator() {;} //Kell inicializalni? (Nem)
   103       EdgeIterator(const EdgeIterator &i) {G=i.G;e=i.e;}
   105       EdgeIterator(const EdgeIterator &i) {G=i.G;e=i.e;}
   104       
   106       
   105       // Lehet, hogy ez a ketto nem kell!!!
   107       // Lehet, hogy ez a ketto nem kell!!!
   106       
   108       
   107       NodeIterator From() const {NodeIterator i;i.G=G;i.n=e->From();return i;}
   109       NodeIterator tail() const {NodeIterator i;i.G=G;i.n=e->From();return i;}
   108       NodeIterator To() const {NodeIterator i;i.G=G;i.n=e->To();return i;}
   110       NodeIterator head() const {NodeIterator i;i.G=G;i.n=e->To();return i;}
   109       
   111       NodeIterator opposite(const NodeIterator &n) const
   110       bool isValid() {return e;}
   112       {return n==tail()?head():tail();}
       
   113       
       
   114       bool valid() {return e;}
   111       E &operator*() const { return G->Data(e); }
   115       E &operator*() const { return G->Data(e); }
   112       E *operator->() const { return &G->Data(e); }
   116       E *operator->() const { return &G->Data(e); }
   113       
   117       
   114       //operator const OutEdgeIterator ();
   118       //operator const OutEdgeIterator ();
   115       //operator const InEdgeIterator ();
   119       //operator const InEdgeIterator ();
   117       //operator const SymEdgeIterator(); //Ez kerdeses, mit csinal
   121       //operator const SymEdgeIterator(); //Ez kerdeses, mit csinal
   118       
   122       
   119       bool operator==(const EdgeIterator &i) const {return e==i.e;}
   123       bool operator==(const EdgeIterator &i) const {return e==i.e;}
   120       bool operator!=(const EdgeIterator &i) const {return e!=i.e;}
   124       bool operator!=(const EdgeIterator &i) const {return e!=i.e;}
   121        
   125        
   122       int Index() const { return e.index.block*EDGE_BLOCK_SIZE+e.index.index; }
   126       int Index() const {return e->index.block*EDGE_BLOCK_SIZE+e->index.index;}
   123       //If the edges are indexable 
   127       //If the edges are indexable 
   124 
   128 
   125       friend class Graph;
   129       friend class Graph;
   126       friend class InEdgeIterator;
   130       friend class InEdgeIterator;
   127       friend class OutEdgeIterator;
   131       friend class OutEdgeIterator;
   128       friend class BiEdgeIterator;
   132       friend class BiEdgeIterator;
   129       friend class SymEdgeIterator;
   133       friend class SymEdgeIterator;
   130       friend class AllEdgeIterator;
   134       friend class EachEdgeIterator;
   131     };
   135     };
   132     
   136     
   133     class BiEdgeIterator : public EdgeIterator
   137     class BiEdgeIterator : public EdgeIterator
   134     {
   138     {
   135     public:
   139     public:
   136       BiEdgeIterator &GoNextIn()  { e=e->NextIn(); return *this;}
   140       BiEdgeIterator &goNextIn()  { e=e->NextIn(); return *this;}
   137       BiEdgeIterator &GoNextOut() { e=e->NextOut(); return *this;}
   141       BiEdgeIterator &goNextOut() { e=e->NextOut(); return *this;}
   138       BiEdgeIterator NextIn() const  {return BiEdgeIterator(*this).GoNextIn();}
   142       BiEdgeIterator nextIn() const  {return BiEdgeIterator(*this).goNextIn();}
   139       BiEdgeIterator NextOut() const {return BiEdgeIterator(*this).GoNextOut();}
   143       BiEdgeIterator nextOut() const {return BiEdgeIterator(*this).goNextOut();}
   140       
   144       
   141       operator InEdgeIterator ()
   145       operator InEdgeIterator ()
   142       {InEdgeIterator i; i.G=G;i.e=e;return i;}
   146       {InEdgeIterator i; i.G=G;i.e=e;return i;}
   143       operator OutEdgeIterator ()
   147       operator OutEdgeIterator ()
   144       {OutEdgeIterator i; i.G=G;i.e=e;return i;}
   148       {OutEdgeIterator i; i.G=G;i.e=e;return i;}
   150     class InEdgeIterator : public EdgeIterator
   154     class InEdgeIterator : public EdgeIterator
   151     //Ne a BiEdgeIterator-bol szarmazzon?
   155     //Ne a BiEdgeIterator-bol szarmazzon?
   152     {
   156     {
   153     public:
   157     public:
   154       InEdgeIterator() {}
   158       InEdgeIterator() {}
   155       InEdgeIterator(const Graph<N,E> &Gr,const NodeIterator &n)
   159       InEdgeIterator(Graph<N,E> &Gr,const NodeIterator &n)
   156       { G=&Gr; e=Gr.OldGraph<N,E>::FirstIn(n.n);}
   160       { G=&Gr; e=Gr.OldGraph<N,E>::FirstIn(n.n);}
   157 
   161 
   158       InEdgeIterator &GoNext() { e=e->NextIn(); return *this;}
   162       InEdgeIterator &GoNext() { e=e->NextIn(); return *this;}
   159       InEdgeIterator Next() const {return InEdgeIterator(*this).GoNext();}
   163       InEdgeIterator Next() const {return InEdgeIterator(*this).GoNext();}
   160       InEdgeIterator &operator++() { return GoNext();}
   164       InEdgeIterator &operator++() { return GoNext();}
   178     public:
   182     public:
   179       OutEdgeIterator() {}
   183       OutEdgeIterator() {}
   180       OutEdgeIterator(Graph<N,E> &Gr,const NodeIterator &n)
   184       OutEdgeIterator(Graph<N,E> &Gr,const NodeIterator &n)
   181       { G=&Gr; e=Gr.OldGraph<N,E>::FirstOut(n.n);}
   185       { G=&Gr; e=Gr.OldGraph<N,E>::FirstOut(n.n);}
   182 
   186 
   183       OutEdgeIterator &GoNext() { e=e->NextOut(); return *this;}
   187       OutEdgeIterator &goNext() { e=e->NextOut(); return *this;}
   184       OutEdgeIterator Next() const {return OutEdgeIterator(*this).GoNext();}
   188       OutEdgeIterator next() const {return OutEdgeIterator(*this).goNext();}
   185       OutEdgeIterator &operator++() { return GoNext();}
   189       OutEdgeIterator &operator++() { return goNext();}
   186       OutEdgeIterator operator++(int)
   190       OutEdgeIterator operator++(int)
   187       {OutEdgeIterator tmp(*this); GoNext(); return tmp;}
   191       {OutEdgeIterator tmp(*this); goNext(); return tmp;}
   188       
   192       
   189       NodeIterator Anode() const {return From();}
   193       NodeIterator aNode() const {return tail();}
   190       NodeIterator Bnode() const {return To();}
   194       NodeIterator bNode() const {return head();}
   191       
   195       
   192       operator const InEdgeIterator ()
   196       operator const InEdgeIterator ()
   193       {InEdgeIterator i; i.G=G;i.e=e;return i;}
   197       {InEdgeIterator i; i.G=G;i.e=e;return i;}
   194       operator const BiEdgeIterator ()
   198       operator const BiEdgeIterator ()
   195       {BiEdgeIterator i; i.G=G;i.e=e;return i;}
   199       {BiEdgeIterator i; i.G=G;i.e=e;return i;}
   202     {
   206     {
   203       NodeIterator n;  // Itt ketszer van a G
   207       NodeIterator n;  // Itt ketszer van a G
   204       
   208       
   205     public:
   209     public:
   206       SymEdgeIterator() {}
   210       SymEdgeIterator() {}
   207       SymEdgeIterator(const Graph<N,E> &Gr,const NodeIterator &nn)
   211       SymEdgeIterator(Graph<N,E> &Gr,const NodeIterator &nn)
   208       { G=&Gr; n=nn; e=Gr.FirstSym(nn.n); }
   212       { G=&Gr; n=nn; e=Gr.OldGraph<N,E>::FirstEdge(nn.n); }
   209 
   213 
   210       SymEdgeIterator &GoNext() { e=e->NextEdge(n.n); return *this;}
   214       SymEdgeIterator &goNext() { e=G->NextEdge(n.n,e); return *this;}
   211       SymEdgeIterator Next() const {return SymEdgeIterator(*this).GoNext();}
   215       SymEdgeIterator next() const {return SymEdgeIterator(*this).goNext();}
   212       SymEdgeIterator &operator++() { return GoNext();}
   216       SymEdgeIterator &operator++() { return goNext();}
   213       SymEdgeIterator operator++(int)
   217       SymEdgeIterator operator++(int)
   214       {SymEdgeIterator tmp(*this); GoNext(); return tmp;}
   218       {SymEdgeIterator tmp(*this); goNext(); return tmp;}
   215       
   219       
   216       NodeIterator Anode() const {return n;}
   220       NodeIterator aNode() const {return n;}
   217       NodeIterator Bnode() const {return n.n==From().n?To():From();}
   221       NodeIterator bNode() const {return n.n==tail().n?head():tail();}
   218       
   222       
   219       operator const InEdgeIterator ()
   223       operator const InEdgeIterator ()
   220       {InEdgeIterator i; i.G=G;i.e=e;return i;}
   224       {InEdgeIterator i; i.G=G;i.e=e;return i;}
   221       operator const OutEdgeIterator ()
   225       operator const OutEdgeIterator ()
   222       {OutEdgeIterator i; i.G=G;i.e=e;return i;}
   226       {OutEdgeIterator i; i.G=G;i.e=e;return i;}
   224       {BiEdgeIterator i; i.G=G;i.e=e;return i;}
   228       {BiEdgeIterator i; i.G=G;i.e=e;return i;}
   225       
   229       
   226       friend class Graph;
   230       friend class Graph;
   227     };
   231     };
   228     
   232     
   229     class AllEdgeIterator : public EdgeIterator
   233     class EachEdgeIterator : public EdgeIterator
   230     {
   234     {
   231       NodeIterator n;  // Itt ketszer van a G
   235       NodeIterator n;  // Itt ketszer van a G
   232       
   236       
   233     public:
   237     public:
   234       AllEdgeIterator() {}
   238       EachEdgeIterator() {}
   235       AllEdgeIterator(Graph<N,E> &Gr) : n(Gr)
   239       EachEdgeIterator(Graph<N,E> &Gr) : n(Gr)
   236       {
   240       {
   237 	e=n.isValid()?Gr.OldGraph<N,E>::FirstOut(n.n):NULL;
   241 	e=n.valid()?Gr.OldGraph<N,E>::FirstOut(n.n):NULL;
   238       }  
   242       }  
   239 
   243 
   240       AllEdgeIterator &GoNext()
   244       EachEdgeIterator &goNext()
   241       {
   245       {
   242 	e=e->NextOut();
   246 	e=e->NextOut();
   243 	if(!e && (++n).isValid()) e=G->OldGraph<N,E>::FirstOut(n.n);
   247 	if(!e && (++n).valid()) e=G->OldGraph<N,E>::FirstOut(n.n);
   244 	return *this;
   248 	return *this;
   245       }
   249       }
   246       AllEdgeIterator Next() const {return AllEdgeIterator(*this).GoNext();}
   250       EachEdgeIterator next() const {return EachEdgeIterator(*this).goNext();}
   247       AllEdgeIterator &operator++() { return GoNext();}
   251       EachEdgeIterator &operator++() { return goNext();}
   248       AllEdgeIterator operator++(int)
   252       EachEdgeIterator operator++(int)
   249 	{AllEdgeIterator tmp(*this); GoNext(); return tmp;}
   253 	{EachEdgeIterator tmp(*this); goNext(); return tmp;}
   250       
   254       
   251       
   255       
   252       NodeIterator Anode() const {return n;}
   256       NodeIterator aNode() const {return n;}
   253       NodeIterator Bnode() const {return n.n==From().n?To():From();}
   257       NodeIterator bNode() const {return n.n==tail().n?head():tail();}
   254       
   258       
       
   259       operator const EdgeIterator ()
       
   260       {EdgeIterator i; i.G=G;i.e=e;return i;}
   255       operator const InEdgeIterator ()
   261       operator const InEdgeIterator ()
   256       {InEdgeIterator i; i.G=G;i.e=e;return i;}
   262       {InEdgeIterator i; i.G=G;i.e=e;return i;}
   257       operator const OutEdgeIterator ()
   263       operator const OutEdgeIterator ()
   258       {OutEdgeIterator i; i.G=G;i.e=e;return i;}
   264       {OutEdgeIterator i; i.G=G;i.e=e;return i;}
   259       operator const BiEdgeIterator ()
   265       operator const BiEdgeIterator ()
   267     typedef BiEdgeIterator DeletingBiEdgeIterator;
   273     typedef BiEdgeIterator DeletingBiEdgeIterator;
   268     typedef OutEdgeIterator DeletingOutEdgeIterator;
   274     typedef OutEdgeIterator DeletingOutEdgeIterator;
   269     typedef InEdgeIterator DeletingInEdgeIterator;
   275     typedef InEdgeIterator DeletingInEdgeIterator;
   270     typedef SymEdgeIterator DeletingSymEdgeIterator;
   276     typedef SymEdgeIterator DeletingSymEdgeIterator;
   271     
   277     
   272     const NodeIterator FirstNode()
   278     const NodeIterator firstNode()
   273     {
   279     {
   274       NodeIterator i;
   280       NodeIterator i;
   275       i.G=this;i.n=OldGraph<N,E>::FirstNode();
   281       i.G=this;i.n=OldGraph<N,E>::FirstNode();
   276       return i;
   282       return i;
   277     }
   283     }
   278     
   284     
   279     void GetFirst(NodePoint &p)   { p=OldGraph<N,E>::FirstNode(); }
   285     void getFirst(NodeIt &p)   { p=OldGraph<N,E>::FirstNode(); }
   280     
   286     
   281     void GetFirst(InEdgePoint &p,const NodePoint &n)
   287     void getFirst(InEdgeIt &p,const NodeIt &n)
   282     { p=OldGraph<N,E>::FirstIn(n); }
   288     { p=OldGraph<N,E>::FirstIn(n); }
   283     void GetFirst(OutEdgePoint &p,const NodePoint &n)
   289     void getFirst(OutEdgeIt &p,const NodeIt &n)
   284     { p=OldGraph<N,E>::FirstOut(n); }
   290     { p=OldGraph<N,E>::FirstOut(n); }
   285     void GetFirst(SymEdgePoint &p,const NodePoint &n)
   291     void getFirst(SymEdgeIt &p,const NodeIt &n)
   286     { p=OldGraph<N,E>::FirstEdge(n); }
   292     { p=OldGraph<N,E>::FirstEdge(n); }
   287     void GetFirst(EdgePoint &p) //Vegigmegy mindenen
   293     void getFirst(EdgeIt &p) //Vegigmegy mindenen
   288     { p.e=NodeNum()?OldGraph<N,E>::FirstOut(OldGraph<N,E>::FirstNode()):NULL;}
   294     { p.e=nodeNum()?OldGraph<N,E>::FirstOut(OldGraph<N,E>::FirstNode()):NULL;}
   289 
   295 
   290     void GetFirst(NodeIterator &i) { i.G=this;i.n=OldGraph<N,E>::FirstNode();}
   296     void getFirst(NodeIterator &i) { i.G=this;i.n=OldGraph<N,E>::FirstNode();}
   291     
   297     
   292     void GetFirst(InEdgeIterator &i,const NodeIterator &n)
   298     void getFirst(InEdgeIterator &i,const NodeIterator &n)
   293     { i.G=this;i.e=OldGraph<N,E>::FirstIn(n.n); }
   299     { i.G=this;i.e=OldGraph<N,E>::FirstIn(n.n); }
   294     void GetFirst(OutEdgeIterator &i,const NodeIterator &n)
   300     void getFirst(OutEdgeIterator &i,const NodeIterator &n)
   295     { i.G=this;i.e=OldGraph<N,E>::FirstOut(n.n); }
   301     { i.G=this;i.e=OldGraph<N,E>::FirstOut(n.n); }
   296     void GetFirst(SymEdgeIterator &i,const NodeIterator &n)
   302     void getFirst(SymEdgeIterator &i,const NodeIterator &n)
   297     { i.G=this;i.e=OldGraph<N,E>::FirstSym(n.n); }
   303     { i.G=this;i.e=OldGraph<N,E>::FirstEdge(n.n); }
   298     void GetFirst(AllEdgeIterator &i) //Vegigmegy mindenen
   304     void getFirst(EachEdgeIterator &i) //Vegigmegy mindenen
   299     {
   305     {
   300       i.G=this;
   306       i.G=this;
   301       GetFirst(i.n);
   307       getFirst(i.n);
   302       i.e=OldGraph<N,E>::NodeNum()?OldGraph<N,E>::FirstOut(i.n.n):NULL;
   308       i.e=OldGraph<N,E>::NodeNum()?OldGraph<N,E>::FirstOut(i.n.n):NULL;
   303     }  
   309     }  
   304     
   310     
   305     
   311     
   306     
   312     
   307     //Vagy beginnode()?
   313     //Vagy beginnode()?
   308     const DeletingEdgeIterator FirstOut(const NodeIterator &n)
   314     const DeletingEdgeIterator firstOut(const NodeIterator &n)
   309     {
   315     {
   310       EdgeIterator i;
   316       EdgeIterator i;
   311       i.G=n.G;i.edge=n.G->OldGraph<N,E>::FirstOut(n.n);
   317       i.G=n.G;i.edge=n.G->OldGraph<N,E>::FirstOut(n.n);
   312       return i;
   318       return i;
   313     }
   319     }
   314     const DeletingEdgeIterator FirstIn(const NodeIterator &n)
   320     const DeletingEdgeIterator firstIn(const NodeIterator &n)
   315     {
   321     {
   316       EdgeIterator i;
   322       EdgeIterator i;
   317       i.G=n.G;i.edge=n.G->OldGraph<N,E>::FirstIn(n.n);
   323       i.G=n.G;i.edge=n.G->OldGraph<N,E>::FirstIn(n.n);
   318       return i;
   324       return i;
   319     }
   325     }
   320     const DeletingSymEdgeIterator FirstSym(const NodeIterator &n)
   326     const DeletingSymEdgeIterator firstSym(const NodeIterator &n)
   321     {
   327     {
   322       EdgeIterator i;
   328       EdgeIterator i;
   323       i.G=n.G;i.n=n.n;
   329       i.G=n.G;i.n=n.n;
   324       i.edge=n.G->OldGraph<N,E>::FirstEdge(n.n);
   330       i.edge=n.G->OldGraph<N,E>::FirstEdge(n.n);
   325       return i;
   331       return i;
   339       operator const OutEdgeIterator () const
   345       operator const OutEdgeIterator () const
   340       {OutEdgeIterator i; n.G->GetFirst(i,n);return i;}
   346       {OutEdgeIterator i; n.G->GetFirst(i,n);return i;}
   341       operator const SymEdgeIterator () const
   347       operator const SymEdgeIterator () const
   342       {SymEdgeIterator i; n.G->GetFirst(i,n);return i;}
   348       {SymEdgeIterator i; n.G->GetFirst(i,n);return i;}
   343   
   349   
   344       operator const InEdgePoint () const
   350       operator const InEdgeIt () const
   345       {InEdgePoint i; n.G->GetFirst(i,n);return i;}
   351       {InEdgeIt i; n.G->GetFirst(i,n);return i;}
   346       operator const OutEdgePoint () const
   352       operator const OutEdgeIt () const
   347       {OutEdgePoint i; n.G->GetFirst(i,n);return i;}
   353       {OutEdgeIt i; n.G->GetFirst(i,n);return i;}
   348       operator const SymEdgePoint () const
   354       operator const SymEdgeIt () const
   349       {SymEdgePoint i; n.G->GetFirst(i,n);return i;}
   355       {SymEdgeIt i; n.G->GetFirst(i,n);return i;}
   350     };
   356     };
   351     
   357     
   352     class FirstAnythingType
   358     class FirstAnythingType
   353     {
   359     {
   354       Graph<N,E> *G;
   360       Graph<N,E> *G;
   355     public:
   361     public:
   356       FirstAnythingType(Graph<N,E> *gg) : G(gg) {}
   362       FirstAnythingType(Graph<N,E> *gg) : G(gg) {}
   357 
   363 
   358       operator const AllEdgeIterator () const
   364       operator const EachEdgeIterator () const
   359       {AllEdgeIterator i; G->GetFirst(i);return i;}  
   365       {EachEdgeIterator i; G->GetFirst(i);return i;}  
   360       operator const EdgePoint () const
   366       operator const EdgeIt () const
   361       {EdgePoint i; G->GetFirst(i);return i;}
   367       {EdgeIt i; G->GetFirst(i);return i;}
   362       operator const NodeIterator () const
   368       operator const NodeIterator () const
   363       {NodeIterator i; G->GetFirst(i);return i;}  
   369       {NodeIterator i; G->GetFirst(i);return i;}  
   364       operator const NodePoint () const
   370       operator const NodeIt () const
   365       {NodePoint i; G->GetFirst(i);return i;}
   371       {NodeIt i; G->GetFirst(i);return i;}
   366     } _FST;
   372     } _FST;
   367     
   373     
   368     //    const NodeIterator First() {NodeIterator i;GetFirst(i); return i;}
   374     //    const NodeIterator First() {NodeIterator i;GetFirst(i); return i;}
   369     FirstAnythingTypeNode First(NodeIterator &i)
   375     FirstAnythingTypeNode first(NodeIterator &i)
   370     {FirstAnythingTypeNode t(i); return t;}
   376     {FirstAnythingTypeNode t(i); return t;}
   371     const FirstAnythingType &First() {return _FST;}
   377     const FirstAnythingType &first() {return _FST;}
   372     
   378     
   373     // LastNode() vagy endnode() stb. Nem kell?
   379     // LastNode() vagy endnode() stb. Nem kell?
   374     
   380     
   375     DeletingNodeIterator AddNode()
   381     DeletingNodeIterator addNode()
   376     {
   382     {
   377       DeletingNodeIterator i;
   383       DeletingNodeIterator i;
   378       i.G=this; i.n=OldGraph<N,E>::AddNode();
   384       i.G=this; i.n=OldGraph<N,E>::AddNode();
   379       return i;
   385       return i;
   380     }
   386     }
   381     DeletingEdgeIterator
   387     DeletingEdgeIterator
   382     AddEdge(const NodeIterator from,const NodeIterator to)
   388     addEdge(const NodeIterator from,const NodeIterator to)
   383     {
   389     {
   384       DeletingEdgeIterator i;
   390       DeletingEdgeIterator i;
   385       i.G=this;i.e=OldGraph<N,E>::AddEdge(from.n,to.n);return i;
   391       i.G=this;i.e=OldGraph<N,E>::AddEdge(from.n,to.n);return i;
   386     }
   392     }
   387     
   393     
   388     void Delete(DeletingNodeIterator n) {n.G->OldGraph<N,E>::Delete(n.n);}
   394     void Delete(DeletingNodeIterator n) {n.G->OldGraph<N,E>::Delete(n.n);}
   389     void Delete(DeletingEdgeIterator e) {e.G->OldGraph<N,E>::Delete(e.e);}
   395     void Delete(DeletingEdgeIterator e) {e.G->OldGraph<N,E>::Delete(e.e);}
   390     
   396     
   391     int NodeNum() { OldGraph<N,E>::NodeNum(); }
   397     int nodeNum() { OldGraph<N,E>::NodeNum(); }
   392     void Clean() { OldGraph<N,E>::Clean(); }
   398     void clean() { OldGraph<N,E>::Clean(); }
   393 
   399 
   394     Graph() : _FST(this) {}
   400     Graph() : _FST(this) {}
   395 
   401 
   396     // MAPS:
   402     // MAPS:
   397     template<class T> class NodeMap
   403     template<class T> class NodeMap
   399       Graph<N,E> *G;
   405       Graph<N,E> *G;
   400       vector<T> map;
   406       vector<T> map;
   401 
   407 
   402     public:
   408     public:
   403       typedef T value_type;
   409       typedef T value_type;
   404       void Put(const NodeIterator i, const T &t) {map[i.Index()]=t;}
   410       void put(const NodeIterator i, const T &t) {map[i.Index()]=t;}
   405       T Get(const NodeIterator i) const {return map[i.Index()];}
   411       T get(const NodeIterator i) const {return map[i.Index()];}
   406       T operator[](NodeIterator i) {return map[i.Index()];}
   412       T operator[](NodeIterator i) {return map[i.Index()];}
   407 
   413 
   408       void update() { map.resize(G->MaxNode());}
   414       void update() { map.resize(G->MaxNode());}
   409 
   415 
   410       NodeMap() {}
   416       NodeMap() {}
   411       void SetG(Graph<N,E> &Gr) { G=&Gr; update();}      
   417       void setG(Graph<N,E> &Gr) { G=&Gr; update();}      
   412     };
   418     };
   413 
   419 
   414     template<class T> class EdgeMap
   420     template<class T> class EdgeMap
   415     {
   421     {
   416       Graph<N,E> *G;
   422       Graph<N,E> *G;
   417       vector<T> map;
   423       vector<T> map;
   418 
   424 
   419     public:
   425     public:
   420       typedef T value_type;
   426       typedef T value_type;
   421       void Put(const NodeIterator i, const T &t) {map[i.Index()]=t;}
   427       void put(const EdgeIterator i, const T &t) {map[i.Index()]=t;}
   422       T &Get(const NodeIterator i) {return map[i.Index()];}
   428       T get(const EdgeIterator i) const {return map[i.Index()];}
   423       T &operator[](NodeIterator i) {return map[i.Index()];}
   429       T &operator[](EdgeIterator i) {return map[i.Index()];}
   424       
   430       
   425       void update()
   431       void update()
   426 	{ map.resize(G->MaxEdge());}
   432 	{ map.resize(G->MaxEdge());}
   427       
   433       
   428       EdgeMap() {}
   434       EdgeMap() {}
   429       void SetG(Graph<N,E> &Gr) 
   435       void setG(Graph<N,E> &Gr) 
   430       { G=&Gr ;update();}
   436       { G=&Gr ;update();}
   431       
   437       
   432     };
   438     };
   433     
   439     
   434 
   440 
   435     int MaxNode() { return OldGraph<N,E>::MaxNode();}
   441     int maxNode() { return OldGraph<N,E>::MaxNode();}
   436     int MaxEdge() { return ::edge_block_num*EDGE_BLOCK_SIZE;}
   442     int maxEdge() { return ::edge_block_num*EDGE_BLOCK_SIZE;}
   437     
   443     
       
   444   };
       
   445   
       
   446   template <class G> //G is a graph-type
       
   447   class Path
       
   448   {
       
   449   public:
       
   450     typedef G Graph;
       
   451     typedef typename G::NodeIterator NodeIterator;
       
   452     typedef typename G::EdgeIterator EdgeIterator;
       
   453     typedef typename G::SymEdgeIterator SymEdgeIterator;
       
   454     
       
   455   private:
       
   456     std::vector<EdgeIterator> path;
       
   457     std::vector<bool> reversed;
       
   458 
       
   459   public:
       
   460     void setLength(int n) { path.resize(n);reversed.resize(n);}
       
   461     int getLength() { return path.size(); }
       
   462     EdgeIterator &operator[](int n) {return path[n];}
       
   463     NodeIterator GetNode(int n) // What about path of length 1?
       
   464     {
       
   465       return n?
       
   466 	reversed[n-1]?path[n-1].tail():path[n-1].head():
       
   467 	reversed[0]?path[0].head():path[0].tail();
       
   468     }
       
   469     void setRevert(int n,bool r=true) {reversed[n]=r;}
       
   470     void setEdge(int n,SymEdgeIterator i)
       
   471     {
       
   472       path[n]=i;
       
   473       reversed[n] = i.head()==i.aNode();
       
   474     }
       
   475     void setEdge(int n,EdgeIterator i,bool r)
       
   476     {
       
   477       path[n]=i;
       
   478       reversed[n] = r;
       
   479     }
       
   480 
       
   481     NodeIterator tail() { return getNode(0); }
       
   482     NodeIterator head() { return getNode(getLength()); }
   438   };
   483   };
   439   
   484   
   440   /*   Ez itt a fiam kommentje:
   485   /*   Ez itt a fiam kommentje:
   441        <v n  nnnnnnnnnnnnnncncccccccccccccccccvvvvvv
   486        <v n  nnnnnnnnnnnnnncncccccccccccccccccvvvvvv
   442        vvnvnvnvnvnvvnnvnvnvnnvnbbbvfffffvvffffffffffffffffffffz
   487        vvnvnvnvnvnvvnnvnvnvnnvnbbbvfffffvvffffffffffffffffffffz
   443        <<  < < <  < <  <   .cx..x.c.cc.c          
   488        <<  < < <  < <  <   .cx..x.c.cc.c          
   444        mcmn   
   489        mcmn   
   445   */
   490   */
   446   
   491 };
   447 }
       
   448 
   492 
   449 #endif
   493 #endif