src/work/alpar/gwrapper.h
author marci
Mon, 20 Sep 2004 17:53:33 +0000
changeset 890 3a48bc350e0f
parent 145 07c32a103bbb
child 921 818510fa3d99
permissions -rw-r--r--
Specialized ConstMap for defining constant maps at compile time, by klao.
Time comparision of the generic and specialized maps.
alpar@65
     1
// -*-mode: c++; -*-
alpar@103
     2
#ifndef GRAPH_WRAPPER_H
alpar@103
     3
#define GRAPH_WRAPPER_H
alpar@103
     4
alpar@105
     5
namespace hugo {
alpar@65
     6
alpar@65
     7
template<typename G>
alpar@65
     8
class TrivGraphWrapper
alpar@65
     9
{
alpar@65
    10
  G *graph;
alpar@65
    11
  
alpar@65
    12
public:
alpar@65
    13
  typedef G BaseGraph;
alpar@65
    14
alpar@65
    15
  typedef typename G::EdgeIt EdgeIt;
alpar@65
    16
  
alpar@65
    17
  typedef typename G::InEdgeIt InEdgeIt;
alpar@65
    18
  typedef typename G::OutEdgeIt OutEdgeIt;
alpar@65
    19
  typedef typename G::SymEdgeIt SymEdgeIt;
alpar@65
    20
  typedef typename G::EachEdgeIt EachEdgeIt;
alpar@65
    21
alpar@65
    22
  typedef typename G::NodeIt NodeIt;
alpar@65
    23
    
alpar@65
    24
  template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
alpar@65
    25
  template<typename I,typename P> I &getFirst(I &i,const P &p);
alpar@65
    26
  { return graph->getFirst(i,p); }
alpar@65
    27
  template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@65
    28
  template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@65
    29
alpar@65
    30
  NodeIt head(const EdgeIt &e);
alpar@65
    31
  { return graph->head(e); }
alpar@65
    32
  NodeIt tail(const EdgeIt &e);
alpar@65
    33
  { return graph->tail(e); }
alpar@65
    34
  
alpar@65
    35
  template<typename I> NodeIt aNode(const I e);
alpar@65
    36
  { return graph->aNode(e); }
alpar@65
    37
  template<typename I> NodeIt bNode(const I e);
alpar@65
    38
  { return graph->bNode(e); }
alpar@65
    39
  
alpar@65
    40
  template<typename I> bool valid(const I i);
alpar@65
    41
  { return graph->valid(i); }
alpar@65
    42
  
alpar@65
    43
  template<typename I> void setInvalid(const I &i);
alpar@65
    44
  { return graph->setInvalid(i); }
alpar@65
    45
  
alpar@65
    46
  NodeIt addNode(); { return graph->addNode(); }
alpar@65
    47
  EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@65
    48
  { return graph->addEdge(ftom,to); }
alpar@65
    49
  
alpar@65
    50
  template<I> void delete(I i); { graph->delete(i); }
alpar@65
    51
  
alpar@65
    52
  void clean();  { graph->clean(); }
alpar@65
    53
  
alpar@65
    54
  template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@65
    55
  template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@65
    56
  
alpar@65
    57
  void SetG(G &g) {graph = &g;}
alpar@65
    58
  
alpar@65
    59
  TrivGraphWrapper() {graph = NULL;}
alpar@65
    60
  TrivGraphWrapper(G &g) {graph = &g;}
alpar@65
    61
};
alpar@65
    62
alpar@65
    63
template<typename G>
alpar@65
    64
class RevGraphWrapper
alpar@65
    65
{
alpar@65
    66
  G *graph;
alpar@65
    67
  
alpar@65
    68
public:
alpar@65
    69
  typedef G BaseGraph;
alpar@65
    70
alpar@65
    71
  typedef typename G::EdgeIt EdgeIt;
alpar@65
    72
  
alpar@65
    73
  typedef typename G::InEdgeIt OutEdgeIt;
alpar@65
    74
  typedef typename G::OutEdgeIt InEdgeIt;
alpar@65
    75
  typedef typename G::SymEdgeIt SymEdgeIt;
alpar@65
    76
  typedef typename G::EachEdgeIt EachEdgeIt;
alpar@65
    77
alpar@65
    78
  typedef typename G::NodeIt NodeIt;
alpar@65
    79
    
alpar@65
    80
  template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
alpar@65
    81
  template<typename I,typename P> I &getFirst(I &i,const P &p);
alpar@65
    82
  { return graph->getFirst(i,p); }
alpar@65
    83
  template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@65
    84
  template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@65
    85
alpar@65
    86
  NodeIt head(const EdgeIt &e);
alpar@65
    87
  { return graph->tail(e); }
alpar@65
    88
  NodeIt tail(const EdgeIt &e);
alpar@65
    89
  { return graph->head(e); }
alpar@65
    90
  
alpar@65
    91
  template<typename I> NodeIt aNode(const I e);
alpar@65
    92
  { return graph->aNode(e); }
alpar@65
    93
  template<typename I> NodeIt bNode(const I e);
alpar@65
    94
  { return graph->bNode(e); }
alpar@65
    95
  
alpar@65
    96
  template<typename I> bool valid(const I i);
alpar@65
    97
  { return graph->valid(i); }
alpar@65
    98
  
alpar@65
    99
  template<typename I> void setInvalid(const I &i);
alpar@65
   100
  { return graph->setInvalid(i); }
alpar@65
   101
  
alpar@65
   102
  NodeIt addNode(); { return graph->addNode(); }
alpar@65
   103
  EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@65
   104
  { return graph->addEdge(to,from); }
alpar@65
   105
  
alpar@65
   106
  template<I> void delete(I i); { graph->delete(i); }
alpar@65
   107
  
alpar@65
   108
  void clean();  { graph->clean(); }
alpar@65
   109
  
alpar@65
   110
  template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@65
   111
  template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@65
   112
  
alpar@65
   113
  void SetG(G &g) {graph = &g;}
alpar@65
   114
  
alpar@65
   115
  RevGraphWrapper() {graph = NULL;}
alpar@65
   116
  RevGraphWrapper(G &g) {graph = &g;}
alpar@65
   117
};
alpar@65
   118
alpar@70
   119
template<typename G>
alpar@145
   120
class RevGraphExt : public G
alpar@145
   121
{
alpar@145
   122
public:
alpar@145
   123
  //  typedef G BaseGraph;
alpar@145
   124
alpar@145
   125
  typedef typename G::EdgeIt EdgeIt;
alpar@145
   126
  
alpar@145
   127
  typedef typename G::InEdgeIt OutEdgeIt;
alpar@145
   128
  typedef typename G::OutEdgeIt InEdgeIt;
alpar@145
   129
  typedef typename G::SymEdgeIt SymEdgeIt;
alpar@145
   130
  typedef typename G::EachEdgeIt EachEdgeIt;
alpar@145
   131
alpar@145
   132
  typedef typename G::NodeIt NodeIt;
alpar@145
   133
    
alpar@145
   134
//   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
alpar@145
   135
//   template<typename I,typename P> I &getFirst(I &i,const P &p);
alpar@145
   136
//   { return graph->getFirst(i,p); }
alpar@145
   137
//   template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@145
   138
//   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@145
   139
alpar@145
   140
  NodeIt head(const EdgeIt &e);
alpar@145
   141
  { return G::tail(e); }
alpar@145
   142
  NodeIt tail(const EdgeIt &e);
alpar@145
   143
  { return G::head(e); }
alpar@145
   144
  
alpar@145
   145
//   template<typename I> NodeIt aNode(const I e);
alpar@145
   146
//   { return graph->aNode(e); }
alpar@145
   147
//   template<typename I> NodeIt bNode(const I e);
alpar@145
   148
//   { return graph->bNode(e); }
alpar@145
   149
  
alpar@145
   150
//   template<typename I> bool valid(const I i);
alpar@145
   151
//   { return graph->valid(i); }
alpar@145
   152
  
alpar@145
   153
//   template<typename I> void setInvalid(const I &i);
alpar@145
   154
//   { return graph->setInvalid(i); }
alpar@145
   155
  
alpar@145
   156
//   NodeIt addNode(); { return graph->addNode(); }
alpar@145
   157
alpar@145
   158
  EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@145
   159
  { return G::addEdge(to,from); }
alpar@145
   160
  
alpar@145
   161
//   template<I> void delete(I i); { graph->delete(i); }
alpar@145
   162
  
alpar@145
   163
//   void clean();  { graph->clean(); }
alpar@145
   164
  
alpar@145
   165
//   template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@145
   166
//   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@145
   167
  
alpar@145
   168
//   void SetG(G &g) {graph = &g;}
alpar@145
   169
  
alpar@145
   170
//   RevGraphWrapper() {graph = NULL;}
alpar@145
   171
//   RevGraphWrapper(G &g) {graph = &g;}
alpar@145
   172
};
alpar@145
   173
alpar@145
   174
template<typename G>
alpar@70
   175
class SymGraphWrapper
alpar@70
   176
{
alpar@70
   177
  G *graph;
alpar@70
   178
  
alpar@70
   179
public:
alpar@70
   180
  typedef G BaseGraph;
alpar@70
   181
alpar@70
   182
  typedef typename G::EdgeIt EdgeIt;
alpar@70
   183
  
alpar@147
   184
  typedef typename G::SymEdgeIt InEdgeIt;
alpar@147
   185
  typedef typename G::SymEdgeIt OutEdgeIt;
alpar@70
   186
  typedef typename G::SymEdgeIt SymEdgeIt;
alpar@70
   187
  typedef typename G::EachEdgeIt EachEdgeIt;
alpar@70
   188
alpar@70
   189
  typedef typename G::NodeIt NodeIt;
alpar@70
   190
    
alpar@70
   191
  template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
alpar@70
   192
  template<typename I,typename P> I &getFirst(I &i,const P &p);
alpar@70
   193
  { return graph->getFirst(i,p); }
alpar@70
   194
  template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@70
   195
  template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@70
   196
alpar@70
   197
  NodeIt head(const EdgeIt &e);
alpar@70
   198
  { return graph->head(e); }
alpar@70
   199
  NodeIt tail(const EdgeIt &e);
alpar@70
   200
  { return graph->tail(e); }
alpar@70
   201
  
alpar@70
   202
  template<typename I> NodeIt aNode(const I e);
alpar@70
   203
  { return graph->aNode(e); }
alpar@70
   204
  template<typename I> NodeIt bNode(const I e);
alpar@70
   205
  { return graph->bNode(e); }
alpar@70
   206
  
alpar@70
   207
  template<typename I> bool valid(const I i);
alpar@70
   208
  { return graph->valid(i); }
alpar@70
   209
  
alpar@70
   210
  template<typename I> void setInvalid(const I &i);
alpar@70
   211
  { return graph->setInvalid(i); }
alpar@70
   212
  
alpar@70
   213
  NodeIt addNode(); { return graph->addNode(); }
alpar@70
   214
  EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@70
   215
  { return graph->addEdge(to,from); }
alpar@70
   216
  
alpar@70
   217
  template<I> void delete(I i); { graph->delete(i); }
alpar@70
   218
  
alpar@70
   219
  void clean();  { graph->clean(); }
alpar@70
   220
  
alpar@70
   221
  template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@70
   222
  template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@70
   223
  
alpar@70
   224
  void SetG(G &g) {graph = &g;}
alpar@70
   225
  
alpar@70
   226
  RevGraphWrapper() {graph = NULL;}
alpar@70
   227
  RevGraphWrapper(G &g) {graph = &g;}
alpar@70
   228
};
alpar@70
   229
alpar@70
   230
alpar@145
   231
alpar@145
   232
alpar@145
   233
alpar@145
   234
alpar@145
   235
alpar@145
   236
alpar@145
   237
alpar@145
   238
alpar@145
   239
alpar@145
   240
alpar@145
   241
alpar@145
   242
alpar@145
   243
alpar@145
   244
alpar@145
   245
alpar@145
   246
alpar@145
   247
alpar@70
   248
// FIXME: comparison should be made better!!!
alpar@70
   249
template<typename G, typename lomap, typename fmap, typename himap>
alpar@70
   250
class ResGraphWrapper
alpar@70
   251
{
alpar@70
   252
  G *graph;
alpar@70
   253
  
alpar@70
   254
public:
alpar@70
   255
  typedef G BaseGraph;
alpar@70
   256
alpar@70
   257
  typedef typename G::EdgeIt EdgeIt;
alpar@70
   258
  
alpar@70
   259
  class InEdgeIt 
alpar@70
   260
  {
alpar@70
   261
  public:
alpar@70
   262
    G::NodeIt n;
alpar@70
   263
    G::InEdgeIt i;   
alpar@70
   264
    G::OutEdgeIt o;
alpar@70
   265
  }
alpar@70
   266
  class OutEdgeIt 
alpar@70
   267
  {
alpar@70
   268
  public:
alpar@70
   269
    G::NodeIt n;
alpar@70
   270
    G::InEdgeIt i;   
alpar@70
   271
    G::OutEdgeIt o;
alpar@70
   272
  }
alpar@70
   273
  typedef typename G::SymEdgeIt SymEdgeIt;
alpar@70
   274
  typedef typename G::EachEdgeIt EachEdgeIt;
alpar@70
   275
alpar@70
   276
  typedef typename G::NodeIt NodeIt;
alpar@70
   277
    
alpar@70
   278
  NodeIt &getFirst(NodeIt &n); { return graph->getFirst(n); }
alpar@70
   279
alpar@70
   280
  // EachEdge and SymEdge  is missing!!!!
alpar@70
   281
  // EdgeIt <-> In/OutEdgeIt conversion is missing!!!!
alpar@70
   282
alpar@70
   283
  InEdgeIt &getFirst(InEdgeIt &e,const NodeIt &n)
alpar@70
   284
  {
alpar@70
   285
    e.n=n;
alpar@70
   286
    graph->getFirst(e.i,n);
alpar@70
   287
    while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
alpar@70
   288
      graph->goNext(e.i);
alpar@70
   289
    if(!graph->valid(e.i)) {
alpar@70
   290
      graph->getFirst(e.o,n);
alpar@70
   291
      while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
alpar@70
   292
	graph->goNext(e.o);
alpar@70
   293
    }
alpar@70
   294
    return e;
alpar@70
   295
  }
alpar@70
   296
  InEdgeIt &goNext(InEdgeIt &e)
alpar@70
   297
  {
alpar@70
   298
    if(graph->valid(e.i)) {
alpar@70
   299
      while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
alpar@70
   300
	graph->goNext(e.i);
alpar@70
   301
      if(graph->valid(e.i)) return e;
alpar@70
   302
      else graph->getFirst(e.o,e.n);
alpar@70
   303
    }
alpar@70
   304
    else {
alpar@70
   305
      while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
alpar@70
   306
	graph->goNext(e.o);
alpar@70
   307
      return e;
alpar@70
   308
    }
alpar@70
   309
  }
alpar@70
   310
  InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
alpar@70
   311
  bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
alpar@70
   312
alpar@70
   313
  OutEdgeIt &getFirst(OutEdgeIt &e,const NodeIt &n)
alpar@70
   314
  {
alpar@70
   315
    e.n=n;
alpar@70
   316
    graph->getFirst(e.o,n);
alpar@70
   317
    while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
alpar@70
   318
      graph->goNext(e.o);
alpar@70
   319
    if(!graph->valid(e.o)) {
alpar@70
   320
      graph->getFirst(e.i,n);
alpar@70
   321
      while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
alpar@70
   322
	graph->goNext(e.i);
alpar@70
   323
    }
alpar@70
   324
    return e;
alpar@70
   325
  }
alpar@70
   326
  OutEdgeIt &goNext(OutEdgeIt &e)
alpar@70
   327
  {
alpar@70
   328
    if(graph->valid(e.o)) {
alpar@70
   329
      while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
alpar@70
   330
	graph->goNext(e.o);
alpar@70
   331
      if(graph->valid(e.o)) return e;
alpar@70
   332
      else graph->getFirst(e.i,e.n);
alpar@70
   333
    }
alpar@70
   334
    else {
alpar@70
   335
      while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
alpar@70
   336
	graph->goNext(e.i);
alpar@70
   337
      return e;
alpar@70
   338
    }
alpar@70
   339
  }
alpar@70
   340
  OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
alpar@70
   341
  bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
alpar@70
   342
alpar@70
   343
  template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@70
   344
  template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@70
   345
alpar@70
   346
  NodeIt head(const EdgeIt &e);
alpar@70
   347
  { return graph->head(e); }
alpar@70
   348
  NodeIt tail(const EdgeIt &e);
alpar@70
   349
  { return graph->tail(e); }
alpar@70
   350
  
alpar@70
   351
  template<typename I> NodeIt aNode(const I e);
alpar@70
   352
  { return graph->aNode(e); }
alpar@70
   353
  template<typename I> NodeIt bNode(const I e);
alpar@70
   354
  { return graph->bNode(e); }
alpar@70
   355
  
alpar@70
   356
  template<typename I> bool valid(const I i);
alpar@70
   357
  { return graph->valid(i); }
alpar@70
   358
  
alpar@70
   359
  template<typename I> void setInvalid(const I &i);
alpar@70
   360
  { return graph->setInvalid(i); }
alpar@70
   361
  
alpar@70
   362
  NodeIt addNode(); { return graph->addNode(); }
alpar@70
   363
  EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@70
   364
  { return graph->addEdge(to,from); }
alpar@70
   365
  
alpar@70
   366
  template<I> void delete(I i); { graph->delete(i); }
alpar@70
   367
  
alpar@70
   368
  void clean();  { graph->clean(); }
alpar@70
   369
  
alpar@70
   370
  template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@70
   371
  template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@70
   372
  
alpar@70
   373
  void SetG(G &g) {graph = &g;}
alpar@70
   374
  
alpar@70
   375
  RevGraphWrapper() {graph = NULL;}
alpar@70
   376
  RevGraphWrapper(G &g) {graph = &g;}
alpar@70
   377
};
alpar@70
   378
alpar@65
   379
alpar@65
   380
alpar@65
   381
//   NodeIt &getFirst(NodeIt &n) { return graph->getFirst(n); }
alpar@65
   382
//   InEdgeIt &getFirst(InEdgeIt &e,const NodeIt &n);
alpar@65
   383
//   { return graph->getFirst(e,n); }
alpar@65
   384
//   OutEdgeIt &getFirst(OutEdgeIt &e,const NodeIt &n);
alpar@65
   385
//   { return graph->getFirst(e,n); }
alpar@65
   386
//   SymEdgeIt &getFirst(SymEdgeIt &e,const NodeIt &n);
alpar@65
   387
//   { return graph->getFirst(e,n); }
alpar@65
   388
//   EachEdgeIt &getFirst(EachEdgeIt &e);
alpar@65
   389
//   { return graph->getFirst(e); }
alpar@65
   390
   
alpar@65
   391
//   NodeIt next(const NodeIt &n);
alpar@65
   392
//   { return graph->next(n); }
alpar@65
   393
//   InEdgeIt next(const InEdgeIt &e);
alpar@65
   394
//   { return graph->next(e); }
alpar@65
   395
//   OutEdgeIt next(const OutEdgeIt &e);
alpar@65
   396
//   { return graph->next(e); }
alpar@65
   397
//   SymEdgeIt next(const SymEdgeIt &e);
alpar@65
   398
//   { return graph->next(e); }
alpar@65
   399
//   EachEdgeIt next(const EachEdgeIt &e);
alpar@65
   400
//   { return graph->next(e); }
alpar@65
   401
 
alpar@65
   402
//   NodeIt &goNext(NodeIt &n);
alpar@65
   403
//   { return graph->goNext(n); }
alpar@65
   404
//   InEdgeIt &goNext(InEdgeIt &e);
alpar@65
   405
//   { return graph->goNext(e); }
alpar@65
   406
//   OutEdgeIt &goNext(OutEdgeIt &e);
alpar@65
   407
//   { return graph->goNext(e); }
alpar@65
   408
//   SymEdgeIt &goNext(SymEdgeIt &e);
alpar@65
   409
//   { return graph->goNext(e); }
alpar@65
   410
//   EachEdgeIt &goNext(EachEdgeIt &e);
alpar@65
   411
//   { return graph->goNext(e); }
alpar@65
   412