lemon/ugraph_adaptor.h
changeset 2387 317b9a88c350
parent 2381 0248790c66ea
child 2391 14a343be7a5a
equal deleted inserted replaced
12:9c6aaa672885 13:b97e6dd1872d
    97     typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
    97     typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
    98     int edgeNum() const { return graph->edgeNum(); }
    98     int edgeNum() const { return graph->edgeNum(); }
    99     int uEdgeNum() const { return graph->uEdgeNum(); }
    99     int uEdgeNum() const { return graph->uEdgeNum(); }
   100 
   100 
   101     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   101     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   102     Edge findEdge(const Node& source, const Node& target, 
   102     Edge findEdge(const Node& u, const Node& v, 
   103 		  const Edge& prev = INVALID) {
   103 		  const Edge& prev = INVALID) {
   104       return graph->findEdge(source, target, prev);
   104       return graph->findEdge(u, v, prev);
   105     }
   105     }
   106     UEdge findUEdge(const Node& source, const Node& target, 
   106     UEdge findUEdge(const Node& u, const Node& v, 
   107                     const UEdge& prev = INVALID) {
   107                     const UEdge& prev = INVALID) {
   108       return graph->findUEdge(source, target, prev);
   108       return graph->findUEdge(u, v, prev);
   109     }
   109     }
   110   
   110   
   111     Node addNode() const { return graph->addNode(); }
   111     Node addNode() const { return graph->addNode(); }
   112     UEdge addEdge(const Node& source, const Node& target) const { 
   112     UEdge addEdge(const Node& u, const Node& v) const { 
   113       return graph->addEdge(source, target); 
   113       return graph->addEdge(u, v); 
   114     }
   114     }
   115 
   115 
   116     void erase(const Node& i) const { graph->erase(i); }
   116     void erase(const Node& i) const { graph->erase(i); }
   117     void erase(const UEdge& i) const { graph->erase(i); }
   117     void erase(const UEdge& i) const { graph->erase(i); }
   118   
   118   
   123 
   123 
   124     int id(const Node& v) const { return graph->id(v); }
   124     int id(const Node& v) const { return graph->id(v); }
   125     int id(const Edge& e) const { return graph->id(e); }
   125     int id(const Edge& e) const { return graph->id(e); }
   126     int id(const UEdge& e) const { return graph->id(e); }
   126     int id(const UEdge& e) const { return graph->id(e); }
   127 
   127 
   128     Node fromNodeId(int id) const {
   128     Node fromNodeId(int ix) const {
   129       return graph->fromNodeId(id);
   129       return graph->fromNodeId(ix);
   130     }
   130     }
   131 
   131 
   132     Edge fromEdgeId(int id) const {
   132     Edge fromEdgeId(int ix) const {
   133       return graph->fromEdgeId(id);
   133       return graph->fromEdgeId(ix);
   134     }
   134     }
   135 
   135 
   136     UEdge fromUEdgeId(int id) const {
   136     UEdge fromUEdgeId(int ix) const {
   137       return graph->fromUEdgeId(id);
   137       return graph->fromUEdgeId(ix);
   138     }
   138     }
   139 
   139 
   140     int maxNodeId() const {
   140     int maxNodeId() const {
   141       return graph->maxNodeId();
   141       return graph->maxNodeId();
   142     }
   142     }
   393 
   393 
   394     typedef False NodeNumTag;
   394     typedef False NodeNumTag;
   395     typedef False EdgeNumTag;
   395     typedef False EdgeNumTag;
   396 
   396 
   397     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   397     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   398     Edge findEdge(const Node& source, const Node& target, 
   398     Edge findEdge(const Node& u, const Node& v, 
   399 		  const Edge& prev = INVALID) {
   399 		  const Edge& prev = INVALID) {
   400       if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
   400       if (!(*node_filter_map)[u] || !(*node_filter_map)[v]) {
   401         return INVALID;
   401         return INVALID;
   402       }
   402       }
   403       Edge edge = Parent::findEdge(source, target, prev);
   403       Edge edge = Parent::findEdge(u, v, prev);
   404       while (edge != INVALID && !(*uedge_filter_map)[edge]) {
   404       while (edge != INVALID && !(*uedge_filter_map)[edge]) {
   405         edge = Parent::findEdge(source, target, edge);
   405         edge = Parent::findEdge(u, v, edge);
   406       }
   406       }
   407       return edge;
   407       return edge;
   408     }
   408     }
   409     UEdge findUEdge(const Node& source, const Node& target, 
   409     UEdge findUEdge(const Node& u, const Node& v, 
   410 		  const UEdge& prev = INVALID) {
   410 		  const UEdge& prev = INVALID) {
   411       if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
   411       if (!(*node_filter_map)[u] || !(*node_filter_map)[v]) {
   412         return INVALID;
   412         return INVALID;
   413       }
   413       }
   414       UEdge uedge = Parent::findUEdge(source, target, prev);
   414       UEdge uedge = Parent::findUEdge(u, v, prev);
   415       while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
   415       while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
   416         uedge = Parent::findUEdge(source, target, uedge);
   416         uedge = Parent::findUEdge(u, v, uedge);
   417       }
   417       }
   418       return uedge;
   418       return uedge;
   419     }
   419     }
   420 
   420 
   421     template <typename _Value>
   421     template <typename _Value>
   426     public:
   426     public:
   427       typedef Adaptor Graph;
   427       typedef Adaptor Graph;
   428       typedef SubMapExtender<Adaptor, typename Parent::
   428       typedef SubMapExtender<Adaptor, typename Parent::
   429                              template NodeMap<_Value> > Parent;
   429                              template NodeMap<_Value> > Parent;
   430     
   430     
   431       NodeMap(const Graph& graph) 
   431       NodeMap(const Graph& g) 
   432 	: Parent(graph) {}
   432 	: Parent(g) {}
   433       NodeMap(const Graph& graph, const _Value& value) 
   433       NodeMap(const Graph& g, const _Value& v) 
   434 	: Parent(graph, value) {}
   434 	: Parent(g, v) {}
   435     
   435     
   436       NodeMap& operator=(const NodeMap& cmap) {
   436       NodeMap& operator=(const NodeMap& cmap) {
   437 	return operator=<NodeMap>(cmap);
   437 	return operator=<NodeMap>(cmap);
   438       }
   438       }
   439     
   439     
   452     public:
   452     public:
   453       typedef Adaptor Graph;
   453       typedef Adaptor Graph;
   454       typedef SubMapExtender<Adaptor, typename Parent::
   454       typedef SubMapExtender<Adaptor, typename Parent::
   455                              template EdgeMap<_Value> > Parent;
   455                              template EdgeMap<_Value> > Parent;
   456     
   456     
   457       EdgeMap(const Graph& graph) 
   457       EdgeMap(const Graph& g) 
   458 	: Parent(graph) {}
   458 	: Parent(g) {}
   459       EdgeMap(const Graph& graph, const _Value& value) 
   459       EdgeMap(const Graph& g, const _Value& v) 
   460 	: Parent(graph, value) {}
   460 	: Parent(g, v) {}
   461     
   461     
   462       EdgeMap& operator=(const EdgeMap& cmap) {
   462       EdgeMap& operator=(const EdgeMap& cmap) {
   463 	return operator=<EdgeMap>(cmap);
   463 	return operator=<EdgeMap>(cmap);
   464       }
   464       }
   465     
   465     
   478     public:
   478     public:
   479       typedef Adaptor Graph;
   479       typedef Adaptor Graph;
   480       typedef SubMapExtender<Adaptor, typename Parent::
   480       typedef SubMapExtender<Adaptor, typename Parent::
   481                              template UEdgeMap<_Value> > Parent;
   481                              template UEdgeMap<_Value> > Parent;
   482     
   482     
   483       UEdgeMap(const Graph& graph) 
   483       UEdgeMap(const Graph& g) 
   484 	: Parent(graph) {}
   484 	: Parent(g) {}
   485       UEdgeMap(const Graph& graph, const _Value& value) 
   485       UEdgeMap(const Graph& g, const _Value& v) 
   486 	: Parent(graph, value) {}
   486 	: Parent(g, v) {}
   487     
   487     
   488       UEdgeMap& operator=(const UEdgeMap& cmap) {
   488       UEdgeMap& operator=(const UEdgeMap& cmap) {
   489 	return operator=<UEdgeMap>(cmap);
   489 	return operator=<UEdgeMap>(cmap);
   490       }
   490       }
   491     
   491     
   620 
   620 
   621     typedef False NodeNumTag;
   621     typedef False NodeNumTag;
   622     typedef False EdgeNumTag;
   622     typedef False EdgeNumTag;
   623 
   623 
   624     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   624     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   625     Edge findEdge(const Node& source, const Node& target, 
   625     Edge findEdge(const Node& u, const Node& v, 
   626 		  const Edge& prev = INVALID) {
   626 		  const Edge& prev = INVALID) {
   627       Edge edge = Parent::findEdge(source, target, prev);
   627       Edge edge = Parent::findEdge(u, v, prev);
   628       while (edge != INVALID && !(*uedge_filter_map)[edge]) {
   628       while (edge != INVALID && !(*uedge_filter_map)[edge]) {
   629         edge = Parent::findEdge(source, target, edge);
   629         edge = Parent::findEdge(u, v, edge);
   630       }
   630       }
   631       return edge;
   631       return edge;
   632     }
   632     }
   633     UEdge findUEdge(const Node& source, const Node& target, 
   633     UEdge findUEdge(const Node& u, const Node& v, 
   634 		  const UEdge& prev = INVALID) {
   634 		  const UEdge& prev = INVALID) {
   635       UEdge uedge = Parent::findUEdge(source, target, prev);
   635       UEdge uedge = Parent::findUEdge(u, v, prev);
   636       while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
   636       while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
   637         uedge = Parent::findUEdge(source, target, uedge);
   637         uedge = Parent::findUEdge(u, v, uedge);
   638       }
   638       }
   639       return uedge;
   639       return uedge;
   640     }
   640     }
   641 
   641 
   642     template <typename _Value>
   642     template <typename _Value>
   647     public:
   647     public:
   648       typedef Adaptor Graph;
   648       typedef Adaptor Graph;
   649       typedef SubMapExtender<Adaptor, typename Parent::
   649       typedef SubMapExtender<Adaptor, typename Parent::
   650                              template NodeMap<_Value> > Parent;
   650                              template NodeMap<_Value> > Parent;
   651     
   651     
   652       NodeMap(const Graph& graph) 
   652       NodeMap(const Graph& g) 
   653 	: Parent(graph) {}
   653 	: Parent(g) {}
   654       NodeMap(const Graph& graph, const _Value& value) 
   654       NodeMap(const Graph& g, const _Value& v) 
   655 	: Parent(graph, value) {}
   655 	: Parent(g, v) {}
   656     
   656     
   657       NodeMap& operator=(const NodeMap& cmap) {
   657       NodeMap& operator=(const NodeMap& cmap) {
   658 	return operator=<NodeMap>(cmap);
   658 	return operator=<NodeMap>(cmap);
   659       }
   659       }
   660     
   660     
   673     public:
   673     public:
   674       typedef Adaptor Graph;
   674       typedef Adaptor Graph;
   675       typedef SubMapExtender<Adaptor, typename Parent::
   675       typedef SubMapExtender<Adaptor, typename Parent::
   676                              template EdgeMap<_Value> > Parent;
   676                              template EdgeMap<_Value> > Parent;
   677     
   677     
   678       EdgeMap(const Graph& graph) 
   678       EdgeMap(const Graph& g) 
   679 	: Parent(graph) {}
   679 	: Parent(g) {}
   680       EdgeMap(const Graph& graph, const _Value& value) 
   680       EdgeMap(const Graph& g, const _Value& v) 
   681 	: Parent(graph, value) {}
   681 	: Parent(g, v) {}
   682     
   682     
   683       EdgeMap& operator=(const EdgeMap& cmap) {
   683       EdgeMap& operator=(const EdgeMap& cmap) {
   684 	return operator=<EdgeMap>(cmap);
   684 	return operator=<EdgeMap>(cmap);
   685       }
   685       }
   686     
   686     
   699     public:
   699     public:
   700       typedef Adaptor Graph;
   700       typedef Adaptor Graph;
   701       typedef SubMapExtender<Adaptor, typename Parent::
   701       typedef SubMapExtender<Adaptor, typename Parent::
   702                              template UEdgeMap<_Value> > Parent;
   702                              template UEdgeMap<_Value> > Parent;
   703     
   703     
   704       UEdgeMap(const Graph& graph) 
   704       UEdgeMap(const Graph& g) 
   705 	: Parent(graph) {}
   705 	: Parent(g) {}
   706       UEdgeMap(const Graph& graph, const _Value& value) 
   706       UEdgeMap(const Graph& g, const _Value& v) 
   707 	: Parent(graph, value) {}
   707 	: Parent(g, v) {}
   708     
   708     
   709       UEdgeMap& operator=(const UEdgeMap& cmap) {
   709       UEdgeMap& operator=(const UEdgeMap& cmap) {
   710 	return operator=<UEdgeMap>(cmap);
   710 	return operator=<UEdgeMap>(cmap);
   711       }
   711       }
   712     
   712     
   941     
   941     
   942     typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
   942     typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
   943     int edgeNum() const { return graph->uEdgeNum(); }
   943     int edgeNum() const { return graph->uEdgeNum(); }
   944 
   944 
   945     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   945     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   946     Edge findEdge(const Node& source, const Node& target, 
   946     Edge findEdge(const Node& u, const Node& v, 
   947 		  const Edge& prev = INVALID) {
   947 		  const Edge& prev = INVALID) {
   948       Edge edge = prev;
   948       Edge edge = prev;
   949       bool d = edge == INVALID ? true : (*direction)[edge];
   949       bool d = edge == INVALID ? true : (*direction)[edge];
   950       if (d) {
   950       if (d) {
   951         edge = graph->findUEdge(source, target, edge);
   951         edge = graph->findUEdge(u, v, edge);
   952         while (edge != INVALID && !(*direction)[edge]) {
   952         while (edge != INVALID && !(*direction)[edge]) {
   953           graph->findUEdge(source, target, edge);
   953           graph->findUEdge(u, v, edge);
   954         }
   954         }
   955         if (edge != INVALID) return edge;
   955         if (edge != INVALID) return edge;
   956       }
   956       }
   957       graph->findUEdge(target, source, edge);
   957       graph->findUEdge(v, u, edge);
   958       while (edge != INVALID && (*direction)[edge]) {
   958       while (edge != INVALID && (*direction)[edge]) {
   959         graph->findUEdge(source, target, edge);
   959         graph->findUEdge(u, v, edge);
   960       }
   960       }
   961       return edge;
   961       return edge;
   962     }
   962     }
   963   
   963   
   964     Node addNode() const { 
   964     Node addNode() const { 
   965       return Node(graph->addNode()); 
   965       return Node(graph->addNode()); 
   966     }
   966     }
   967 
   967 
   968     Edge addEdge(const Node& source, const Node& target) const {
   968     Edge addEdge(const Node& u, const Node& v) const {
   969       Edge edge = graph->addEdge(source, target);
   969       Edge edge = graph->addEdge(u, v);
   970       direction->set(edge, graph->source(edge) == source);
   970       direction->set(edge, graph->source(edge) == u);
   971       return edge; 
   971       return edge; 
   972     }
   972     }
   973 
   973 
   974     void erase(const Node& i) const { graph->erase(i); }
   974     void erase(const Node& i) const { graph->erase(i); }
   975     void erase(const Edge& i) const { graph->erase(i); }
   975     void erase(const Edge& i) const { graph->erase(i); }