From 394757f512ca49a07165bf8a9f054aa3db2d506b Mon Sep 17 00:00:00 2001 From: Nicholas Edmonds Date: Tue, 7 Jul 2009 00:21:15 +0000 Subject: [PATCH] Added add_vertices and add_edges calls with global-to-local maps and resolved ambiguous overloads resulting from the new forms. [SVN r54737] --- .../graph/compressed_sparse_row_graph.hpp | 147 +++++++++++++++--- 1 file changed, 126 insertions(+), 21 deletions(-) diff --git a/include/boost/graph/compressed_sparse_row_graph.hpp b/include/boost/graph/compressed_sparse_row_graph.hpp index 738c5110..1ea2b655 100644 --- a/include/boost/graph/compressed_sparse_row_graph.hpp +++ b/include/boost/graph/compressed_sparse_row_graph.hpp @@ -664,9 +664,8 @@ class compressed_sparse_row_graph // From number of vertices and mutable vectors of sources and targets; // vectors are returned with unspecified contents but are guaranteed not to // share storage with the constructed graph. - template compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_t, - std::vector& sources, + std::vector& sources, std::vector& targets, vertices_size_type numverts, const GraphProperty& prop = GraphProperty()) @@ -681,9 +680,9 @@ class compressed_sparse_row_graph // unspecified contents but are guaranteed not to share storage with the // constructed graph. This constructor should only be used by the // distributed CSR graph. - template + template compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_global_t, - std::vector& sources, + std::vector& sources, std::vector& targets, vertices_size_type numlocalverts, GlobalToLocal global_to_local, @@ -697,9 +696,8 @@ class compressed_sparse_row_graph // From number of vertices and mutable vectors of sources, targets, and edge // properties; vectors are returned with unspecified contents but are // guaranteed not to share storage with the constructed graph. - template compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_t, - std::vector& sources, + std::vector& sources, std::vector& targets, std::vector& edge_props, vertices_size_type numverts, @@ -715,9 +713,9 @@ class compressed_sparse_row_graph // returned with unspecified contents but are guaranteed not to share // storage with the constructed graph. This constructor should only be used // by the distributed CSR graph. - template + template compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_global_t, - std::vector& sources, + std::vector& sources, std::vector& targets, std::vector& edge_props, vertices_size_type numlocalverts, @@ -832,8 +830,8 @@ class compressed_sparse_row_graph // Replace graph with sources and targets given, sorting them in-place, and // using the given global-to-local property map to get local indices from // global ones in the two arrays. - template - void assign_sources_and_targets_global(std::vector& sources, + template + void assign_sources_and_targets_global(std::vector& sources, std::vector& targets, vertices_size_type numverts, GlobalToLocal global_to_local) { @@ -891,8 +889,8 @@ class compressed_sparse_row_graph // Replace graph with sources and targets and edge properties given, sorting // them in-place, and using the given global-to-local property map to get // local indices from global ones in the two arrays. - template - void assign_sources_and_targets_global(std::vector& sources, + template + void assign_sources_and_targets_global(std::vector& sources, std::vector& targets, std::vector& edge_props, vertices_size_type numverts, @@ -1035,12 +1033,14 @@ class compressed_sparse_row_graph #ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE // Add edges from a sorted (smallest sources first) range of pairs and edge // properties - template + template void add_edges_sorted_internal( BidirectionalIteratorOrig first_sorted, BidirectionalIteratorOrig last_sorted, - EPIterOrig ep_iter_sorted) { + EPIterOrig ep_iter_sorted, + const GlobalToLocal& global_to_local) { typedef boost::reverse_iterator BidirectionalIterator; typedef boost::reverse_iterator EPIter; // Flip sequence @@ -1051,6 +1051,7 @@ class compressed_sparse_row_graph typedef typename boost::graph_traits::vertices_size_type vertex_num; typedef typename boost::graph_traits::edges_size_type edge_num; edge_num new_edge_count = std::distance(first, last); + EPIter ep_iter(ep_iter_sorted); std::advance(ep_iter, -(std::ptrdiff_t)new_edge_count); edge_num edges_added_before_i = new_edge_count; // Count increment to add to rowstarts @@ -1064,7 +1065,7 @@ class compressed_sparse_row_graph // edges_added_to_this_vertex = #mbrs of new_edges with first == i edge_num edges_added_to_this_vertex = 0; while (current_new_edge != last) { - if (current_new_edge->first != i) break; + if (get(global_to_local, current_new_edge->first) != i) break; ++current_new_edge; ++current_new_edge_prop; ++edges_added_to_this_vertex; @@ -1101,6 +1102,16 @@ class compressed_sparse_row_graph } } + template + void + add_edges_sorted_internal( + BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, + EPIterOrig ep_iter_sorted) { + add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted, + identity_property_map()); + } + // Add edges from a sorted (smallest sources first) range of pairs template void @@ -1110,10 +1121,33 @@ class compressed_sparse_row_graph add_edges_sorted_internal(first_sorted, last_sorted, detail::default_construct_iterator()); } + template + void + add_edges_sorted_internal_global( + BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, + const GlobalToLocal& global_to_local) { + add_edges_sorted_internal(first_sorted, last_sorted, detail::default_construct_iterator(), + global_to_local); + } + + template + void + add_edges_sorted_internal_global( + BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, + EPIterOrig ep_iter_sorted, + const GlobalToLocal& global_to_local) { + add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted, + global_to_local); + } + // Add edges from a range of (source, target) pairs that are unsorted - template + template inline void - add_edges_internal(InputIterator first, InputIterator last) { + add_edges_internal(InputIterator first, InputIterator last, + const GlobalToLocal& global_to_local) { typedef compressed_sparse_row_graph Graph; typedef typename boost::graph_traits::vertex_descriptor vertex_t; typedef typename boost::graph_traits::vertices_size_type vertex_num; @@ -1122,15 +1156,22 @@ class compressed_sparse_row_graph edge_vector_t new_edges(first, last); if (new_edges.empty()) return; std::sort(new_edges.begin(), new_edges.end()); - add_edges_sorted_internal(new_edges.begin(), new_edges.end()); + add_edges_sorted_internal_global(new_edges.begin(), new_edges.end(), global_to_local); + } + + template + inline void + add_edges_internal(InputIterator first, InputIterator last) { + add_edges_internal(first, last, identity_property_map()); } // Add edges from a range of (source, target) pairs and edge properties that // are unsorted - template + template inline void add_edges_internal(InputIterator first, InputIterator last, - EPIterator ep_iter, EPIterator ep_iter_end) { + EPIterator ep_iter, EPIterator ep_iter_end, + const GlobalToLocal& global_to_local) { typedef compressed_sparse_row_graph Graph; typedef typename boost::graph_traits::vertex_descriptor vertex_t; typedef typename boost::graph_traits::vertices_size_type vertex_num; @@ -1157,7 +1198,17 @@ class compressed_sparse_row_graph boost::make_transform_iterator( new_edges.begin(), boost::detail::my_tuple_get_class - <1, typename inherited_edge_properties::edge_bundled>())); + <1, typename inherited_edge_properties::edge_bundled>()), + global_to_local); + } + + // Add edges from a range of (source, target) pairs and edge properties that + // are unsorted + template + inline void + add_edges_internal(InputIterator first, InputIterator last, + EPIterator ep_iter, EPIterator ep_iter_end) { + add_edges_internal(first, last, ep_iter, ep_iter_end, identity_property_map()); } #endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE @@ -1226,6 +1277,16 @@ add_vertex(BOOST_CSR_GRAPH_TYPE& g) { return old_num_verts_plus_one - 1; } +template +inline Vertex +add_vertex(BOOST_CSR_GRAPH_TYPE& g, + typename BOOST_CSR_GRAPH_TYPE::vertex_bundled const& p) { + Vertex old_num_verts_plus_one = g.m_rowstart.size(); + g.m_rowstart.push_back(EdgeIndex(0)); + g.vertex_properties().push_back(p); + return old_num_verts_plus_one - 1; +} + template inline Vertex add_vertices(typename BOOST_CSR_GRAPH_TYPE::vertices_size_type count, BOOST_CSR_GRAPH_TYPE& g) { @@ -1297,6 +1358,40 @@ add_edge(Vertex src, Vertex tgt, g.add_edges_sorted_internal(first_sorted, last_sorted); } + template + void + add_edges_sorted_global( + BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, + EPIterOrig ep_iter_sorted, + const GlobalToLocal& global_to_local, + BOOST_CSR_GRAPH_TYPE& g) { + g.add_edges_sorted_internal_global(first_sorted, last_sorted, ep_iter_sorted, + global_to_local); + } + + // Add edges from a sorted (smallest sources first) range of pairs + template + void + add_edges_sorted_global( + BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, + const GlobalToLocal& global_to_local, + BOOST_CSR_GRAPH_TYPE& g) { + g.add_edges_sorted_internal_global(first_sorted, last_sorted, global_to_local); + } + + // Add edges from a range of (source, target) pairs that are unsorted + template + inline void + add_edges_global(InputIterator first, InputIterator last, + const GlobalToLocal& global_to_local, BOOST_CSR_GRAPH_TYPE& g) { + g.add_edges_internal(first, last, global_to_local); + } + // Add edges from a range of (source, target) pairs that are unsorted template inline void @@ -1314,6 +1409,16 @@ add_edge(Vertex src, Vertex tgt, BOOST_CSR_GRAPH_TYPE& g) { g.add_edges_internal(first, last, ep_iter, ep_iter_end); } + + template + inline void + add_edges_global(InputIterator first, InputIterator last, + EPIterator ep_iter, EPIterator ep_iter_end, + const GlobalToLocal& global_to_local, + BOOST_CSR_GRAPH_TYPE& g) { + g.add_edges_internal(first, last, ep_iter, ep_iter_end, global_to_local); + } #endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE // From VertexListGraph