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