src/hugo/list_graph.h
changeset 824 157115b5814a
parent 813 65144c52969c
child 825 738abd9d1262
equal deleted inserted replaced
13:dcbaaf28f99b 14:9bda9baef51f
    11 #include <climits>
    11 #include <climits>
    12 
    12 
    13 #include <hugo/invalid.h>
    13 #include <hugo/invalid.h>
    14 
    14 
    15 #include <hugo/map_registry.h>
    15 #include <hugo/map_registry.h>
    16 #include <hugo/default_map_factory.h>
    16 #include <hugo/default_map.h>
    17 
    17 
    18 #include <hugo/sym_map_factory.h>
    18 #include <hugo/sym_map.h>
    19 
    19 
    20 #include <hugo/map_defines.h>
    20 #include <hugo/map_defines.h>
    21 
    21 
    22 
    22 
    23 namespace hugo {
    23 namespace hugo {
    77     class NodeIt;
    77     class NodeIt;
    78     class EdgeIt;
    78     class EdgeIt;
    79     class OutEdgeIt;
    79     class OutEdgeIt;
    80     class InEdgeIt;
    80     class InEdgeIt;
    81 
    81 
       
    82     /// Creating map registries.
    82     CREATE_MAP_REGISTRIES;
    83     CREATE_MAP_REGISTRIES;
    83     CREATE_MAPS(DefaultMapFactory);
    84     /// Creating node and edge maps.
       
    85     CREATE_MAPS(DefaultMap);
    84 
    86 
    85   public:
    87   public:
    86 
    88 
    87     ListGraph() 
    89     ListGraph() 
    88       : nodes(), first_node(-1),
    90       : nodes(), first_node(-1),
   441   {
   443   {
   442   public:
   444   public:
   443 
   445 
   444     typedef SymListGraph Graph;
   446     typedef SymListGraph Graph;
   445 
   447 
   446     KEEP_NODE_MAP(ListGraph);
   448     /// Importing maps from the base class ListGraph.
   447     KEEP_EDGE_MAP(ListGraph);
   449     KEEP_MAPS(ListGraph, SymListGraph);
   448 
   450 
       
   451     /// Creating symmetric map registry.
   449     CREATE_SYM_EDGE_MAP_REGISTRY;
   452     CREATE_SYM_EDGE_MAP_REGISTRY;
   450     CREATE_SYM_EDGE_MAP_FACTORY(DefaultMapFactory);
   453     /// Creating symmetric edge map.
   451     IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
   454     CREATE_SYM_EDGE_MAP(DefaultMap);
   452 
   455 
   453     SymListGraph() : ListGraph() { }
   456     SymListGraph() : ListGraph() { }
   454     SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
   457     SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
   455     ///Adds a pair of oppositely directed edges to the graph.
   458     ///Adds a pair of oppositely directed edges to the graph.
   456     Edge addEdge(Node u, Node v)
   459     Edge addEdge(Node u, Node v)
   527     class NodeIt;
   530     class NodeIt;
   528     class EdgeIt;
   531     class EdgeIt;
   529     class OutEdgeIt;
   532     class OutEdgeIt;
   530     class InEdgeIt;
   533     class InEdgeIt;
   531     
   534     
   532     CREATE_MAP_REGISTRIES;
   535     /// Creating node map registry.
   533     CREATE_MAPS(DefaultMapFactory);
   536     CREATE_NODE_MAP_REGISTRY;
       
   537     /// Creating node maps.
       
   538     CREATE_NODE_MAP(DefaultMap);
       
   539 
       
   540     /// Creating empty map structure for edges.
       
   541     template <typename Value>
       
   542     class EdgeMap {
       
   543     public:
       
   544       EdgeMap() {}
       
   545       EdgeMap(const Graph&) {}
       
   546       EdgeMap(const Graph&, const Value&) {}
       
   547 
       
   548       EdgeMap(const EdgeMap&) {}
       
   549       template <typename CMap> EdgeMap(const CMap&) {}
       
   550 
       
   551       EdgeMap& operator=(const EdgeMap&) {}
       
   552       template <typename CMap> EdgeMap& operator=(const CMap&) {}
       
   553       
       
   554       class ConstIterator {
       
   555       public:
       
   556 	bool operator==(const ConstIterator&) {return true;}
       
   557 	bool operator!=(const ConstIterator&) {return false;}
       
   558       };
       
   559 
       
   560       typedef ConstIterator Iterator;
       
   561       
       
   562       Iterator begin() { return Iterator();}
       
   563       Iterator end() { return Iterator();}
       
   564 
       
   565       ConstIterator begin() const { return ConstIterator();}
       
   566       ConstIterator end() const { return ConstIterator();}
       
   567 
       
   568     };
   534     
   569     
   535   public:
   570   public:
   536 
   571 
   537     ///Default constructor
   572     ///Default constructor
   538     NodeSet() 
   573     NodeSet() 
   846     class EdgeIt;
   881     class EdgeIt;
   847     class OutEdgeIt;
   882     class OutEdgeIt;
   848     class InEdgeIt;
   883     class InEdgeIt;
   849 
   884 
   850 
   885 
       
   886     /// Creating edge map registry.
   851     CREATE_EDGE_MAP_REGISTRY;
   887     CREATE_EDGE_MAP_REGISTRY;
   852     CREATE_EDGE_MAP_FACTORY(DefaultMapFactory);
   888     /// Creating edge maps.
   853     IMPORT_EDGE_MAP(EdgeMapFactory);
   889     CREATE_EDGE_MAP(DefaultMap);
       
   890 
       
   891     /// Importing node maps from the NodeGraphType.
       
   892     IMPORT_NODE_MAP(NodeGraphType, graph.G, EdgeSet, graph);
   854     
   893     
   855     
   894     
   856   public:
   895   public:
   857 
   896 
   858     ///Constructor
   897     ///Constructor
  1088       InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
  1127       InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
  1089       InEdgeIt(const EdgeSet& _G,Node v)
  1128       InEdgeIt(const EdgeSet& _G,Node v)
  1090 	: Edge(_G.nodes[v].first_in), G(&_G) { }
  1129 	: Edge(_G.nodes[v].first_in), G(&_G) { }
  1091       InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
  1130       InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
  1092     };
  1131     };
  1093 
  1132     
  1094     
       
  1095     template <typename V> class NodeMap 
       
  1096       : public NodeGraphType::template NodeMap<V>
       
  1097     {
       
  1098       //This is a must, the constructors need it.
       
  1099       typedef typename NodeGraphType::template NodeMap<V> MapImpl;
       
  1100       typedef V Value;
       
  1101     public:
       
  1102       NodeMap() : MapImpl() {}
       
  1103       
       
  1104       NodeMap(const EdgeSet& graph) 
       
  1105 	: MapImpl(graph.G) { }
       
  1106 
       
  1107       NodeMap(const EdgeSet& graph, const Value& value) 
       
  1108 	: MapImpl(graph.G, value) { }
       
  1109 
       
  1110       NodeMap(const NodeMap& copy) 
       
  1111 	: MapImpl(static_cast<const MapImpl&>(copy)) {}
       
  1112 
       
  1113       template<typename CMap>
       
  1114       NodeMap(const CMap& copy)
       
  1115 	: MapImpl(copy) { }
       
  1116 
       
  1117       NodeMap& operator=(const NodeMap& copy) {
       
  1118 	MapImpl::operator=(static_cast<const MapImpl&>(copy));
       
  1119 	return *this;
       
  1120       }
       
  1121 
       
  1122       template <typename CMap>
       
  1123       NodeMap& operator=(const CMap& copy) {
       
  1124 	MapImpl::operator=(copy);
       
  1125 	return *this;
       
  1126       }
       
  1127 
       
  1128     };
       
  1129   };
  1133   };
  1130 
  1134 
  1131   template<typename GG>
  1135   template<typename GG>
  1132   inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
  1136   inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
  1133 
  1137