src/include/graph.h
changeset 6 b63d1bc367f7
parent 3 272a5677bd6d
child 8 cd54905012bc
equal deleted inserted replaced
2:ab235e7323d6 3:fbb0ceb906ac
     2 #ifndef __GRAPH_H_
     2 #ifndef __GRAPH_H_
     3 #define __GRAPH_H_
     3 #define __GRAPH_H_
     4 
     4 
     5 //inline void *operator new(size_t s, void *p) { return p; }
     5 //inline void *operator new(size_t s, void *p) { return p; }
     6 #include <new>
     6 #include <new>
       
     7 #include <vector>
     7 
     8 
     8 namespace NEGRO 
     9 namespace NEGRO 
     9 {
    10 {
    10   using namespace std;
    11   using namespace std;
    11   
    12   
    38     class OutEdgeIterator;
    39     class OutEdgeIterator;
    39     class BiEdgeIterator;
    40     class BiEdgeIterator;
    40     class SymEdgeIterator;
    41     class SymEdgeIterator;
    41     class AllEdgeIterator;
    42     class AllEdgeIterator;
    42     
    43     
    43     class FirstAnythingTypeNode;
    44     class FirstAnythingTypeNode; //Required by the unified First() function.
    44 
    45 
    45     friend class NodeIterator;
    46     friend class NodeIterator;
    46     friend class EdgeIterator;
    47     friend class EdgeIterator;
    47     friend class InEdgeIterator;
    48     friend class InEdgeIterator;
    48     friend class OutEdgeIterator;
    49     friend class OutEdgeIterator;
   389     
   390     
   390     int NodeNum() { OldGraph<N,E>::NodeNum(); }
   391     int NodeNum() { OldGraph<N,E>::NodeNum(); }
   391     void Clean() { OldGraph<N,E>::Clean(); }
   392     void Clean() { OldGraph<N,E>::Clean(); }
   392 
   393 
   393     Graph() : _FST(this) {}
   394     Graph() : _FST(this) {}
       
   395 
       
   396     // MAPS:
       
   397     template<class T> class NodeMap
       
   398     {
       
   399       Graph<N,E> *G;
       
   400       vector<T> map;
       
   401 
       
   402     public:
       
   403       typedef T value_type;
       
   404       void Set(NodeIterator i, const T &t) {map[i.Index()]=t;}
       
   405       T &Get(NodeIterator i) {return map[i.Index()];}
       
   406       T &operator[](NodeIterator i) {return map[i.Index()];}
       
   407 
       
   408       void update() { map.resize(G->OldGraph<N,E>::NodeMax());}
       
   409 
       
   410       NodeMap(Graph<N,E> &Gr) : map(Gr.OldGraph<N,E>::NodeMax()) { G=&Gr ;}
       
   411       
       
   412     };
       
   413 
       
   414     template<class T> class EdgeMap
       
   415     {
       
   416       Graph<N,E> *G;
       
   417       vector<T> map;
       
   418 
       
   419     public:
       
   420       typedef T value_type;
       
   421       void Set(NodeIterator i, const T &t) {map[i.Index()]=t;}
       
   422       T &Get(NodeIterator i) {return map[i.Index()];}
       
   423       T &operator[](NodeIterator i) {return map[i.Index()];}
       
   424       
       
   425       void update()
       
   426 	{ map.resize(Gr.OldGraph<N,E>::edge_block_num*EDGE_BLOCK_SIZE);}
       
   427       
       
   428       EdgeMap(Graph<N,E> &Gr) 
       
   429 	:map(Gr.OldGraph<N,E>::edge_block_num*EDGE_BLOCK_SIZE)
       
   430 	{ G=&Gr ;}
       
   431       
       
   432     };
       
   433     
   394   };
   434   };
   395   
   435   
   396   /*   Ez itt a fiam kommentje:
   436   /*   Ez itt a fiam kommentje:
   397        <v n  nnnnnnnnnnnnnncncccccccccccccccccvvvvvv
   437        <v n  nnnnnnnnnnnnnncncccccccccccccccccvvvvvv
   398        vvnvnvnvnvnvvnnvnvnvnnvnbbbvfffffvvffffffffffffffffffffz
   438        vvnvnvnvnvnvvnnvnvnvnnvnbbbvfffffvvffffffffffffffffffffz