src/work/deba/test_graph.h
changeset 643 f8053cb51047
parent 595 e10b5e9419ef
child 674 7733d18de0e8
equal deleted inserted replaced
5:bc121911cb69 6:a028af921aca
    28     class EdgeIt;
    28     class EdgeIt;
    29     class OutEdgeIt;
    29     class OutEdgeIt;
    30     class InEdgeIt;
    30     class InEdgeIt;
    31     class SymEdgeIt;
    31     class SymEdgeIt;
    32     
    32     
    33 //    template <typename T> class NodeMap;
    33     //    template <typename T> class NodeMap;
    34 //    template <typename T> class EdgeMap;
    34     //    template <typename T> class EdgeMap;
    35   private:
    35   private:
    36 //    template <typename T> friend class NodeMap;
    36     //    template <typename T> friend class NodeMap;
    37  //   template <typename T> friend class EdgeMap;
    37     //   template <typename T> friend class EdgeMap;
    38  
    38  
    39   private:
    39   private:
    40 
    40 
    41  
    41  
    42 	public:
    42   public:
    43 	
    43 	
    44 		typedef MapBase<ListGraph, Node, NodeIt> NodeMapBase;
    44     typedef MapRegistry<ListGraph, Node, NodeIt> NodeMapRegistry;
    45 		typedef MapRegistry<ListGraph, Node, NodeIt> NodeMapRegistry;
    45     typedef VectorMapFactory<NodeMapRegistry> NodeMapFactory;
    46 		typedef VectorMapFactory<ListGraph, Node, NodeIt> NodeMapFactory;
    46     NodeMapRegistry node_maps;
    47 		NodeMapRegistry node_maps;
    47 
    48 
    48 
    49 
    49 
    50 
    50     typedef MapRegistry<ListGraph, Edge, EdgeIt> EdgeMapRegistry;
    51 		typedef MapBase<ListGraph, Edge, EdgeIt> EdgeMapBase;
    51     typedef VectorMapFactory<EdgeMapRegistry> EdgeMapFactory;
    52 		typedef MapRegistry<ListGraph, Edge, EdgeIt> EdgeMapRegistry;
    52     EdgeMapRegistry edge_maps;
    53 		typedef VectorMapFactory<ListGraph, Edge, EdgeIt> EdgeMapFactory;
       
    54 		EdgeMapRegistry edge_maps;
       
    55  
    53  
    56 
    54 
    57     int node_id;
    55     int node_id;
    58     int edge_id;
    56     int edge_id;
    59     int _node_num;
    57     int _node_num;
   300     int id(Edge e) const { return e.edge->id; }
   298     int id(Edge e) const { return e.edge->id; }
   301 
   299 
   302     /* adding nodes and edges */
   300     /* adding nodes and edges */
   303 
   301 
   304     Node addNode() { 
   302     Node addNode() { 
   305 			Node n = _add_node();
   303       Node n = _add_node();
   306 			node_maps.add(n);
   304       node_maps.add(n);
   307 			return n; 
   305       return n; 
   308 		}
   306     }
   309     Edge addEdge(Node u, Node v) {
   307     Edge addEdge(Node u, Node v) {
   310 			Edge e = _add_edge(u.node, v.node);
   308       Edge e = _add_edge(u.node, v.node);
   311 			edge_maps.add(e);
   309       edge_maps.add(e);
   312       return e; 
   310       return e; 
   313     }
   311     }
   314 
   312 
   315     void erase(Node i) { 
   313     void erase(Node i) { 
   316 			node_maps.erase(i);
   314       node_maps.erase(i);
   317       while (first<OutEdgeIt>(i).valid()) erase(first<OutEdgeIt>(i));
   315       while (first<OutEdgeIt>(i).valid()) erase(first<OutEdgeIt>(i));
   318       while (first<InEdgeIt>(i).valid()) erase(first<InEdgeIt>(i));
   316       while (first<InEdgeIt>(i).valid()) erase(first<InEdgeIt>(i));
   319       _delete_node(i.node); 
   317       _delete_node(i.node); 
   320     }
   318     }
   321   
   319   
   322     void erase(Edge e) { 
   320     void erase(Edge e) { 
   323 			edge_maps.erase(e);
   321       edge_maps.erase(e);
   324 			_delete_edge(e.edge); 
   322       _delete_edge(e.edge); 
   325 		}
   323     }
   326 
   324 
   327     void clear() { 
   325     void clear() { 
   328       while (first<NodeIt>().valid()) erase(first<NodeIt>());
   326       while (first<NodeIt>().valid()) erase(first<NodeIt>());
   329     }
   327     }
   330 
   328 
   508 	return (out_or_in) ? Node(edge->_head) : Node(edge->_tail); }
   506 	return (out_or_in) ? Node(edge->_head) : Node(edge->_tail); }
   509     };
   507     };
   510 
   508 
   511   };
   509   };
   512 
   510 
   513 //   template< typename T >
   511   //   template< typename T >
   514 //   T ListGraph::first() const { 
   512   //   T ListGraph::first() const { 
   515 //     std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>();" << std::endl; 
   513   //     std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>();" << std::endl; 
   516 //     return T(); 
   514   //     return T(); 
   517 //   }
   515   //   }
   518 
   516 
   519 //   template<>
   517   //   template<>
   520 //   ListGraph::NodeIt ListGraph::first<ListGraph::NodeIt>() const { 
   518   //   ListGraph::NodeIt ListGraph::first<ListGraph::NodeIt>() const { 
   521 //     return firstNode(); 
   519   //     return firstNode(); 
   522 //   }
   520   //   }
   523 
   521 
   524 //   template<>
   522   //   template<>
   525 //   ListGraph::EdgeIt ListGraph::first<ListGraph::EdgeIt>() const { 
   523   //   ListGraph::EdgeIt ListGraph::first<ListGraph::EdgeIt>() const { 
   526 //     return firstEdge(); 
   524   //     return firstEdge(); 
   527 //   }
   525   //   }
   528 
   526 
   529 //   template< typename T >
   527   //   template< typename T >
   530 //   T ListGraph::first(ListGraph::Node v) const {
   528   //   T ListGraph::first(ListGraph::Node v) const {
   531 //     std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>(ListGRaph::Node);" << std::endl; 
   529   //     std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>(ListGRaph::Node);" << std::endl; 
   532 //     return T(); 
   530   //     return T(); 
   533 //   } 
   531   //   } 
   534 
   532 
   535 //   template<>
   533   //   template<>
   536 //   ListGraph::OutEdgeIt ListGraph::first<ListGraph::OutEdgeIt>(const ListGraph::Node v) const { 
   534   //   ListGraph::OutEdgeIt ListGraph::first<ListGraph::OutEdgeIt>(const ListGraph::Node v) const { 
   537 //     return firstOutEdge(v); 
   535   //     return firstOutEdge(v); 
   538 //   }
   536   //   }
   539 
   537 
   540 //   template<>
   538   //   template<>
   541 //   ListGraph::InEdgeIt ListGraph::first<ListGraph::InEdgeIt>(const ListGraph::Node v) const { 
   539   //   ListGraph::InEdgeIt ListGraph::first<ListGraph::InEdgeIt>(const ListGraph::Node v) const { 
   542 //     return firstInEdge(v); 
   540   //     return firstInEdge(v); 
   543 //   }
   541   //   }
   544 
   542 
   545 //   template<>
   543   //   template<>
   546 //   ListGraph::SymEdgeIt ListGraph::first<ListGraph::SymEdgeIt>(const ListGraph::Node v) const { 
   544   //   ListGraph::SymEdgeIt ListGraph::first<ListGraph::SymEdgeIt>(const ListGraph::Node v) const { 
   547 //     return firstSymEdge(v); 
   545   //     return firstSymEdge(v); 
   548 //   }
   546   //   }
   549 
   547 
   550 
   548 
   551 } //namespace hugo
   549 } //namespace hugo
   552 
   550 
   553 #endif //HUGO_LIST_GRAPH_H
   551 #endif //HUGO_LIST_GRAPH_H