annotate DEPENDENCIES/generic/include/boost/graph/compressed_sparse_row_graph.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright 2005-2009 The Trustees of Indiana University.
Chris@16 2
Chris@16 3 // Distributed under the Boost Software License, Version 1.0.
Chris@16 4 // (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 5 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6
Chris@16 7 // Authors: Jeremiah Willcock
Chris@16 8 // Douglas Gregor
Chris@16 9 // Andrew Lumsdaine
Chris@16 10
Chris@16 11 // Compressed sparse row graph type
Chris@16 12
Chris@16 13 #ifndef BOOST_GRAPH_COMPRESSED_SPARSE_ROW_GRAPH_HPP
Chris@16 14 #define BOOST_GRAPH_COMPRESSED_SPARSE_ROW_GRAPH_HPP
Chris@16 15
Chris@16 16 #include <vector>
Chris@16 17 #include <utility>
Chris@16 18 #include <algorithm>
Chris@16 19 #include <climits>
Chris@16 20 #include <boost/assert.hpp>
Chris@16 21 #include <iterator>
Chris@16 22 #if 0
Chris@16 23 #include <iostream> // For some debugging code below
Chris@16 24 #endif
Chris@16 25 #include <boost/graph/graph_traits.hpp>
Chris@16 26 #include <boost/graph/properties.hpp>
Chris@16 27 #include <boost/graph/filtered_graph.hpp> // For keep_all
Chris@16 28 #include <boost/graph/detail/indexed_properties.hpp>
Chris@16 29 #include <boost/graph/detail/compressed_sparse_row_struct.hpp>
Chris@16 30 #include <boost/graph/iteration_macros.hpp>
Chris@16 31 #include <boost/iterator/counting_iterator.hpp>
Chris@16 32 #include <boost/iterator/reverse_iterator.hpp>
Chris@16 33 #include <boost/iterator/zip_iterator.hpp>
Chris@16 34 #include <boost/iterator/transform_iterator.hpp>
Chris@16 35 #include <boost/tuple/tuple.hpp>
Chris@16 36 #include <boost/property_map/property_map.hpp>
Chris@16 37 #include <boost/integer.hpp>
Chris@16 38 #include <boost/iterator/iterator_facade.hpp>
Chris@16 39 #include <boost/mpl/if.hpp>
Chris@16 40 #include <boost/utility/enable_if.hpp>
Chris@16 41 #include <boost/graph/graph_selectors.hpp>
Chris@16 42 #include <boost/graph/detail/is_distributed_selector.hpp>
Chris@16 43 #include <boost/graph/properties.hpp>
Chris@16 44 #include <boost/static_assert.hpp>
Chris@16 45 #include <boost/functional/hash.hpp>
Chris@16 46 #include <boost/next_prior.hpp>
Chris@16 47 #include <boost/property_map/transform_value_property_map.hpp>
Chris@16 48 #include <boost/mpl/print.hpp>
Chris@16 49
Chris@16 50 namespace boost {
Chris@16 51
Chris@16 52 // A tag type indicating that the graph in question is a compressed
Chris@16 53 // sparse row graph. This is an internal detail of the BGL.
Chris@16 54 struct csr_graph_tag;
Chris@16 55
Chris@16 56 // A type (edges_are_sorted_t) and a value (edges_are_sorted) used to indicate
Chris@16 57 // that the edge list passed into the CSR graph is already sorted by source
Chris@16 58 // vertex.
Chris@16 59 enum edges_are_sorted_t {edges_are_sorted};
Chris@16 60
Chris@16 61 // A type (edges_are_sorted_global_t) and a value (edges_are_sorted_global)
Chris@16 62 // used to indicate that the edge list passed into the CSR graph is already
Chris@16 63 // sorted by source vertex.
Chris@16 64 enum edges_are_sorted_global_t {edges_are_sorted_global};
Chris@16 65
Chris@16 66 // A type (edges_are_unsorted_t) and a value (edges_are_unsorted) used to
Chris@16 67 // indicate that the edge list passed into the CSR graph is not sorted by
Chris@16 68 // source vertex. This version caches the edge information in memory, and thus
Chris@16 69 // requires only a single pass over the input data.
Chris@16 70 enum edges_are_unsorted_t {edges_are_unsorted};
Chris@16 71
Chris@16 72 // A type (edges_are_unsorted_multi_pass_t) and a value
Chris@16 73 // (edges_are_unsorted_multi_pass) used to indicate that the edge list passed
Chris@16 74 // into the CSR graph is not sorted by source vertex. This version uses less
Chris@16 75 // memory but requires multi-pass capability on the iterators.
Chris@16 76 enum edges_are_unsorted_multi_pass_t {edges_are_unsorted_multi_pass};
Chris@16 77
Chris@16 78 // A type (edges_are_unsorted_multi_pass_global_t) and a value
Chris@16 79 // (edges_are_unsorted_multi_pass_global) used to indicate that the edge list
Chris@16 80 // passed into the CSR graph is not sorted by source vertex. This version uses
Chris@16 81 // less memory but requires multi-pass capability on the iterators. The
Chris@16 82 // global mapping and filtering is done here because it is often faster and it
Chris@16 83 // greatly simplifies handling of edge properties.
Chris@16 84 enum edges_are_unsorted_multi_pass_global_t {edges_are_unsorted_multi_pass_global};
Chris@16 85
Chris@16 86 // A type (construct_inplace_from_sources_and_targets_t) and a value
Chris@16 87 // (construct_inplace_from_sources_and_targets) used to indicate that mutable
Chris@16 88 // vectors of sources and targets (and possibly edge properties) are being used
Chris@16 89 // to construct the CSR graph. These vectors are sorted in-place and then the
Chris@16 90 // targets and properties are swapped into the graph data structure.
Chris@16 91 enum construct_inplace_from_sources_and_targets_t {construct_inplace_from_sources_and_targets};
Chris@16 92
Chris@16 93 // A type (construct_inplace_from_sources_and_targets_global_t) and a value
Chris@16 94 // (construct_inplace_from_sources_and_targets_global) used to indicate that
Chris@16 95 // mutable vectors of sources and targets (and possibly edge properties) are
Chris@16 96 // being used to construct the CSR graph. These vectors are sorted in-place
Chris@16 97 // and then the targets and properties are swapped into the graph data
Chris@16 98 // structure. It is assumed that global indices (for distributed CSR) are
Chris@16 99 // used, and a map is required to convert those to local indices. This
Chris@16 100 // constructor is intended for internal use by the various CSR graphs
Chris@16 101 // (sequential and distributed).
Chris@16 102 enum construct_inplace_from_sources_and_targets_global_t {construct_inplace_from_sources_and_targets_global};
Chris@16 103
Chris@16 104 // A type (edges_are_unsorted_global_t) and a value (edges_are_unsorted_global)
Chris@16 105 // used to indicate that the edge list passed into the CSR graph is not sorted
Chris@16 106 // by source vertex. The data is also stored using global vertex indices, and
Chris@16 107 // must be filtered to choose only local vertices. This constructor caches the
Chris@16 108 // edge information in memory, and thus requires only a single pass over the
Chris@16 109 // input data. This constructor is intended for internal use by the
Chris@16 110 // distributed CSR constructors.
Chris@16 111 enum edges_are_unsorted_global_t {edges_are_unsorted_global};
Chris@16 112
Chris@16 113 /****************************************************************************
Chris@16 114 * Local helper macros to reduce typing and clutter later on. *
Chris@16 115 ****************************************************************************/
Chris@16 116 #define BOOST_CSR_GRAPH_TEMPLATE_PARMS \
Chris@16 117 typename Directed, typename VertexProperty, typename EdgeProperty, \
Chris@16 118 typename GraphProperty, typename Vertex, typename EdgeIndex
Chris@16 119 #define BOOST_CSR_GRAPH_TYPE \
Chris@16 120 compressed_sparse_row_graph<Directed, VertexProperty, EdgeProperty, \
Chris@16 121 GraphProperty, Vertex, EdgeIndex>
Chris@16 122 #define BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS \
Chris@16 123 typename VertexProperty, typename EdgeProperty, \
Chris@16 124 typename GraphProperty, typename Vertex, typename EdgeIndex
Chris@16 125 #define BOOST_DIR_CSR_GRAPH_TYPE \
Chris@16 126 compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, \
Chris@16 127 GraphProperty, Vertex, EdgeIndex>
Chris@16 128 #define BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS \
Chris@16 129 typename VertexProperty, typename EdgeProperty, \
Chris@16 130 typename GraphProperty, typename Vertex, typename EdgeIndex
Chris@16 131 #define BOOST_BIDIR_CSR_GRAPH_TYPE \
Chris@16 132 compressed_sparse_row_graph<bidirectionalS, VertexProperty, EdgeProperty, \
Chris@16 133 GraphProperty, Vertex, EdgeIndex>
Chris@16 134
Chris@16 135 namespace detail {
Chris@16 136 template <typename T>
Chris@16 137 struct default_construct_iterator: public boost::iterator_facade<default_construct_iterator<T>, T, boost::random_access_traversal_tag, const T&> {
Chris@16 138 typedef boost::iterator_facade<default_construct_iterator<T>, T, std::random_access_iterator_tag, const T&> base_type;
Chris@16 139 T saved_value;
Chris@16 140 const T& dereference() const {return saved_value;}
Chris@16 141 bool equal(default_construct_iterator /*i*/) const {return true;}
Chris@16 142 void increment() {}
Chris@16 143 void decrement() {}
Chris@16 144 void advance(typename base_type::difference_type) {}
Chris@16 145 typename base_type::difference_type distance_to(default_construct_iterator) const {return 0;}
Chris@16 146 };
Chris@16 147
Chris@16 148 template <typename Less>
Chris@16 149 struct compare_first {
Chris@16 150 Less less;
Chris@16 151 compare_first(Less less = Less()): less(less) {}
Chris@16 152 template <typename Tuple>
Chris@16 153 bool operator()(const Tuple& a, const Tuple& b) const {
Chris@16 154 return less(a.template get<0>(), b.template get<0>());
Chris@16 155 }
Chris@16 156 };
Chris@16 157
Chris@16 158 template <int N, typename Result>
Chris@16 159 struct my_tuple_get_class {
Chris@16 160 typedef const Result& result_type;
Chris@16 161 template <typename Tuple>
Chris@16 162 result_type operator()(const Tuple& t) const {
Chris@16 163 return t.template get<N>();
Chris@16 164 }
Chris@16 165 };
Chris@16 166 }
Chris@16 167
Chris@16 168 /** Compressed sparse row graph.
Chris@16 169 *
Chris@16 170 * Vertex and EdgeIndex should be unsigned integral types and should
Chris@16 171 * specialize numeric_limits.
Chris@16 172 */
Chris@16 173 template<typename Directed = directedS,
Chris@16 174 typename VertexProperty = no_property,
Chris@16 175 typename EdgeProperty = no_property,
Chris@16 176 typename GraphProperty = no_property,
Chris@16 177 typename Vertex = std::size_t,
Chris@16 178 typename EdgeIndex = Vertex>
Chris@16 179 class compressed_sparse_row_graph; // Not defined
Chris@16 180
Chris@16 181 template<typename VertexProperty,
Chris@16 182 typename EdgeProperty,
Chris@16 183 typename GraphProperty,
Chris@16 184 typename Vertex,
Chris@16 185 typename EdgeIndex>
Chris@16 186 class compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, GraphProperty, Vertex, EdgeIndex>
Chris@16 187 : public detail::indexed_vertex_properties<BOOST_DIR_CSR_GRAPH_TYPE,
Chris@16 188 VertexProperty, Vertex, typed_identity_property_map<Vertex> >
Chris@16 189 {
Chris@16 190 public:
Chris@16 191 typedef detail::indexed_vertex_properties<compressed_sparse_row_graph,
Chris@16 192 VertexProperty, Vertex, typed_identity_property_map<Vertex> >
Chris@16 193 inherited_vertex_properties;
Chris@16 194
Chris@16 195 // Some tests to prevent use of "void" is a property type (as was done in some test cases):
Chris@16 196 BOOST_STATIC_ASSERT((!is_same<VertexProperty, void>::value));
Chris@16 197 BOOST_STATIC_ASSERT((!is_same<EdgeProperty, void>::value));
Chris@16 198 BOOST_STATIC_ASSERT((!is_same<GraphProperty, void>::value));
Chris@16 199
Chris@16 200 public:
Chris@16 201 // For Property Graph
Chris@16 202 typedef GraphProperty graph_property_type;
Chris@16 203 typedef typename lookup_one_property<GraphProperty, graph_bundle_t>::type graph_bundled;
Chris@16 204
Chris@16 205 typedef detail::compressed_sparse_row_structure<EdgeProperty, Vertex, EdgeIndex> forward_type;
Chris@16 206
Chris@16 207 public:
Chris@16 208 /* At this time, the compressed sparse row graph can only be used to
Chris@16 209 * create directed and bidirectional graphs. In the future,
Chris@16 210 * undirected CSR graphs will also be supported.
Chris@16 211 */
Chris@16 212 // BOOST_STATIC_ASSERT((is_same<Directed, directedS>::value));
Chris@16 213
Chris@16 214 // Concept requirements:
Chris@16 215 // For Graph
Chris@16 216 typedef Vertex vertex_descriptor;
Chris@16 217 typedef detail::csr_edge_descriptor<Vertex, EdgeIndex> edge_descriptor;
Chris@16 218 typedef directed_tag directed_category;
Chris@16 219 typedef allow_parallel_edge_tag edge_parallel_category;
Chris@16 220
Chris@16 221 class traversal_category: public incidence_graph_tag,
Chris@16 222 public adjacency_graph_tag,
Chris@16 223 public vertex_list_graph_tag,
Chris@16 224 public edge_list_graph_tag {};
Chris@16 225
Chris@16 226 static vertex_descriptor null_vertex() { return vertex_descriptor(-1); }
Chris@16 227
Chris@16 228 // For VertexListGraph
Chris@16 229 typedef counting_iterator<Vertex> vertex_iterator;
Chris@16 230 typedef Vertex vertices_size_type;
Chris@16 231
Chris@16 232 // For EdgeListGraph
Chris@16 233 typedef EdgeIndex edges_size_type;
Chris@16 234
Chris@16 235 // For IncidenceGraph
Chris@16 236 typedef detail::csr_out_edge_iterator<compressed_sparse_row_graph> out_edge_iterator;
Chris@16 237 typedef EdgeIndex degree_size_type;
Chris@16 238
Chris@16 239 // For AdjacencyGraph
Chris@16 240 typedef typename std::vector<Vertex>::const_iterator adjacency_iterator;
Chris@16 241
Chris@16 242 // For EdgeListGraph
Chris@16 243 typedef detail::csr_edge_iterator<compressed_sparse_row_graph> edge_iterator;
Chris@16 244
Chris@16 245 // For BidirectionalGraph (not implemented)
Chris@16 246 typedef void in_edge_iterator;
Chris@16 247
Chris@16 248 // For internal use
Chris@16 249 typedef csr_graph_tag graph_tag;
Chris@16 250
Chris@16 251 typedef typename forward_type::inherited_edge_properties::edge_bundled edge_bundled;
Chris@16 252 typedef typename forward_type::inherited_edge_properties::edge_push_back_type edge_push_back_type;
Chris@16 253 typedef typename forward_type::inherited_edge_properties::edge_property_type edge_property_type;
Chris@16 254
Chris@16 255 // Constructors
Chris@16 256
Chris@16 257 // Default constructor: an empty graph.
Chris@16 258 compressed_sparse_row_graph(): m_property() {}
Chris@16 259
Chris@16 260 // With numverts vertices
Chris@16 261 compressed_sparse_row_graph(vertices_size_type numverts)
Chris@16 262 : inherited_vertex_properties(numverts), m_forward(numverts) {}
Chris@16 263
Chris@16 264 // From number of vertices and unsorted list of edges
Chris@16 265 template <typename MultiPassInputIterator>
Chris@16 266 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
Chris@16 267 MultiPassInputIterator edge_begin,
Chris@16 268 MultiPassInputIterator edge_end,
Chris@16 269 vertices_size_type numverts,
Chris@16 270 const GraphProperty& prop = GraphProperty())
Chris@16 271 : inherited_vertex_properties(numverts), m_property(prop)
Chris@16 272 {
Chris@16 273 m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, numverts, typed_identity_property_map<vertices_size_type>(), keep_all());
Chris@16 274 }
Chris@16 275
Chris@16 276 // From number of vertices and unsorted list of edges, plus edge properties
Chris@16 277 template <typename MultiPassInputIterator, typename EdgePropertyIterator>
Chris@16 278 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
Chris@16 279 MultiPassInputIterator edge_begin,
Chris@16 280 MultiPassInputIterator edge_end,
Chris@16 281 EdgePropertyIterator ep_iter,
Chris@16 282 vertices_size_type numverts,
Chris@16 283 const GraphProperty& prop = GraphProperty())
Chris@16 284 : inherited_vertex_properties(numverts), m_forward(), m_property(prop)
Chris@16 285 {
Chris@16 286 m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, ep_iter, numverts, typed_identity_property_map<vertices_size_type>(), keep_all());
Chris@16 287 }
Chris@16 288
Chris@16 289 // From number of vertices and unsorted list of edges, with filter and
Chris@16 290 // global-to-local map
Chris@16 291 template <typename MultiPassInputIterator, typename GlobalToLocal, typename SourcePred>
Chris@16 292 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t,
Chris@16 293 MultiPassInputIterator edge_begin,
Chris@16 294 MultiPassInputIterator edge_end,
Chris@16 295 vertices_size_type numlocalverts,
Chris@16 296 const GlobalToLocal& global_to_local,
Chris@16 297 const SourcePred& source_pred,
Chris@16 298 const GraphProperty& prop = GraphProperty())
Chris@16 299 : inherited_vertex_properties(numlocalverts), m_forward(), m_property(prop)
Chris@16 300 {
Chris@16 301 m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, numlocalverts, global_to_local, source_pred);
Chris@16 302 }
Chris@16 303
Chris@16 304 // From number of vertices and unsorted list of edges, plus edge properties,
Chris@16 305 // with filter and global-to-local map
Chris@16 306 template <typename MultiPassInputIterator, typename EdgePropertyIterator, typename GlobalToLocal, typename SourcePred>
Chris@16 307 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t,
Chris@16 308 MultiPassInputIterator edge_begin,
Chris@16 309 MultiPassInputIterator edge_end,
Chris@16 310 EdgePropertyIterator ep_iter,
Chris@16 311 vertices_size_type numlocalverts,
Chris@16 312 const GlobalToLocal& global_to_local,
Chris@16 313 const SourcePred& source_pred,
Chris@16 314 const GraphProperty& prop = GraphProperty())
Chris@16 315 : inherited_vertex_properties(numlocalverts), m_forward(), m_property(prop)
Chris@16 316 {
Chris@16 317 m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, ep_iter, numlocalverts, global_to_local, source_pred);
Chris@16 318 }
Chris@16 319
Chris@16 320 // From number of vertices and sorted list of edges (new interface)
Chris@16 321 template<typename InputIterator>
Chris@16 322 compressed_sparse_row_graph(edges_are_sorted_t,
Chris@16 323 InputIterator edge_begin, InputIterator edge_end,
Chris@16 324 vertices_size_type numverts,
Chris@16 325 edges_size_type numedges = 0,
Chris@16 326 const GraphProperty& prop = GraphProperty())
Chris@16 327 : m_property(prop)
Chris@16 328 {
Chris@16 329 m_forward.assign_from_sorted_edges(edge_begin, edge_end, typed_identity_property_map<vertices_size_type>(), keep_all(), numverts, numedges);
Chris@16 330 inherited_vertex_properties::resize(numverts);
Chris@16 331 }
Chris@16 332
Chris@16 333 // From number of vertices and sorted list of edges (new interface)
Chris@16 334 template<typename InputIterator, typename EdgePropertyIterator>
Chris@16 335 compressed_sparse_row_graph(edges_are_sorted_t,
Chris@16 336 InputIterator edge_begin, InputIterator edge_end,
Chris@16 337 EdgePropertyIterator ep_iter,
Chris@16 338 vertices_size_type numverts,
Chris@16 339 edges_size_type numedges = 0,
Chris@16 340 const GraphProperty& prop = GraphProperty())
Chris@16 341 : m_property(prop)
Chris@16 342 {
Chris@16 343 m_forward.assign_from_sorted_edges(edge_begin, edge_end, ep_iter, typed_identity_property_map<vertices_size_type>(), keep_all(), numverts, numedges);
Chris@16 344 inherited_vertex_properties::resize(numverts);
Chris@16 345 }
Chris@16 346
Chris@16 347 // From number of vertices and sorted list of edges, filtered and global (new interface)
Chris@16 348 template<typename InputIterator, typename GlobalToLocal, typename SourcePred>
Chris@16 349 compressed_sparse_row_graph(edges_are_sorted_global_t,
Chris@16 350 InputIterator edge_begin, InputIterator edge_end,
Chris@16 351 const GlobalToLocal& global_to_local,
Chris@16 352 const SourcePred& source_pred,
Chris@16 353 vertices_size_type numverts,
Chris@16 354 const GraphProperty& prop = GraphProperty())
Chris@16 355 : m_property(prop)
Chris@16 356 {
Chris@16 357 m_forward.assign_from_sorted_edges(edge_begin, edge_end, global_to_local, source_pred, numverts, 0);
Chris@16 358 inherited_vertex_properties::resize(numverts);
Chris@16 359 }
Chris@16 360
Chris@16 361 // From number of vertices and sorted list of edges (new interface)
Chris@16 362 template<typename InputIterator, typename EdgePropertyIterator, typename GlobalToLocal, typename SourcePred>
Chris@16 363 compressed_sparse_row_graph(edges_are_sorted_global_t,
Chris@16 364 InputIterator edge_begin, InputIterator edge_end,
Chris@16 365 EdgePropertyIterator ep_iter,
Chris@16 366 const GlobalToLocal& global_to_local,
Chris@16 367 const SourcePred& source_pred,
Chris@16 368 vertices_size_type numverts,
Chris@16 369 const GraphProperty& prop = GraphProperty())
Chris@16 370 : m_property(prop)
Chris@16 371 {
Chris@16 372 m_forward.assign_from_sorted_edges(edge_begin, edge_end, ep_iter, global_to_local, source_pred, numverts, 0);
Chris@16 373 inherited_vertex_properties::resize(numverts);
Chris@16 374 }
Chris@16 375
Chris@16 376 // From number of vertices and mutable vectors of sources and targets;
Chris@16 377 // vectors are returned with unspecified contents but are guaranteed not to
Chris@16 378 // share storage with the constructed graph.
Chris@16 379 compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_t,
Chris@16 380 std::vector<vertex_descriptor>& sources,
Chris@16 381 std::vector<vertex_descriptor>& targets,
Chris@16 382 vertices_size_type numverts,
Chris@16 383 const GraphProperty& prop = GraphProperty())
Chris@16 384 : inherited_vertex_properties(numverts), m_property(prop)
Chris@16 385 {
Chris@16 386 m_forward.assign_sources_and_targets_global(sources, targets, numverts, boost::typed_identity_property_map<vertices_size_type>());
Chris@16 387 }
Chris@16 388
Chris@16 389 // From number of vertices and mutable vectors of sources and targets,
Chris@16 390 // expressed with global vertex indices; vectors are returned with
Chris@16 391 // unspecified contents but are guaranteed not to share storage with the
Chris@16 392 // constructed graph. This constructor should only be used by the
Chris@16 393 // distributed CSR graph.
Chris@16 394 template <typename GlobalToLocal>
Chris@16 395 compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_global_t,
Chris@16 396 std::vector<vertex_descriptor>& sources,
Chris@16 397 std::vector<vertex_descriptor>& targets,
Chris@16 398 vertices_size_type numlocalverts,
Chris@16 399 GlobalToLocal global_to_local,
Chris@16 400 const GraphProperty& prop = GraphProperty())
Chris@16 401 : inherited_vertex_properties(numlocalverts), m_property(prop)
Chris@16 402 {
Chris@16 403 m_forward.assign_sources_and_targets_global(sources, targets, numlocalverts, global_to_local);
Chris@16 404 }
Chris@16 405
Chris@16 406 // From number of vertices and mutable vectors of sources, targets, and edge
Chris@16 407 // properties; vectors are returned with unspecified contents but are
Chris@16 408 // guaranteed not to share storage with the constructed graph.
Chris@16 409 compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_t,
Chris@16 410 std::vector<vertex_descriptor>& sources,
Chris@16 411 std::vector<vertex_descriptor>& targets,
Chris@16 412 std::vector<typename forward_type::inherited_edge_properties::edge_bundled>& edge_props,
Chris@16 413 vertices_size_type numverts,
Chris@16 414 const GraphProperty& prop = GraphProperty())
Chris@16 415 : inherited_vertex_properties(numverts), m_property(prop)
Chris@16 416 {
Chris@16 417 m_forward.assign_sources_and_targets_global(sources, targets, edge_props, numverts, boost::typed_identity_property_map<vertices_size_type>());
Chris@16 418 }
Chris@16 419
Chris@16 420 // From number of vertices and mutable vectors of sources and targets and
Chris@16 421 // edge properties, expressed with global vertex indices; vectors are
Chris@16 422 // returned with unspecified contents but are guaranteed not to share
Chris@16 423 // storage with the constructed graph. This constructor should only be used
Chris@16 424 // by the distributed CSR graph.
Chris@16 425 template <typename GlobalToLocal>
Chris@16 426 compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_global_t,
Chris@16 427 std::vector<vertex_descriptor>& sources,
Chris@16 428 std::vector<vertex_descriptor>& targets,
Chris@16 429 std::vector<typename forward_type::inherited_edge_properties::edge_bundled>& edge_props,
Chris@16 430 vertices_size_type numlocalverts,
Chris@16 431 GlobalToLocal global_to_local,
Chris@16 432 const GraphProperty& prop = GraphProperty())
Chris@16 433 : inherited_vertex_properties(numlocalverts), m_property(prop)
Chris@16 434 {
Chris@16 435 m_forward.assign_sources_and_targets_global(sources, targets, edge_props, numlocalverts, global_to_local);
Chris@16 436 }
Chris@16 437
Chris@16 438 // From number of vertices and single-pass range of unsorted edges. Data is
Chris@16 439 // cached in coordinate form before creating the actual graph.
Chris@16 440 template<typename InputIterator>
Chris@16 441 compressed_sparse_row_graph(edges_are_unsorted_t,
Chris@16 442 InputIterator edge_begin, InputIterator edge_end,
Chris@16 443 vertices_size_type numverts,
Chris@16 444 const GraphProperty& prop = GraphProperty())
Chris@16 445 : inherited_vertex_properties(numverts), m_property(prop)
Chris@16 446 {
Chris@16 447 std::vector<vertex_descriptor> sources, targets;
Chris@16 448 boost::graph::detail::split_into_separate_coords
Chris@16 449 (edge_begin, edge_end, sources, targets);
Chris@16 450 m_forward.assign_sources_and_targets_global(sources, targets, numverts, boost::typed_identity_property_map<vertices_size_type>());
Chris@16 451 }
Chris@16 452
Chris@16 453 // From number of vertices and single-pass range of unsorted edges and
Chris@16 454 // single-pass range of edge properties. Data is cached in coordinate form
Chris@16 455 // before creating the actual graph.
Chris@16 456 template<typename InputIterator, typename EdgePropertyIterator>
Chris@16 457 compressed_sparse_row_graph(edges_are_unsorted_t,
Chris@16 458 InputIterator edge_begin, InputIterator edge_end,
Chris@16 459 EdgePropertyIterator ep_iter,
Chris@16 460 vertices_size_type numverts,
Chris@16 461 const GraphProperty& prop = GraphProperty())
Chris@16 462 : inherited_vertex_properties(numverts), m_property(prop)
Chris@16 463 {
Chris@16 464 std::vector<vertex_descriptor> sources, targets;
Chris@16 465 boost::graph::detail::split_into_separate_coords
Chris@16 466 (edge_begin, edge_end, sources, targets);
Chris@16 467 size_t numedges = sources.size();
Chris@16 468 std::vector<typename forward_type::inherited_edge_properties::edge_bundled> edge_props(numedges);
Chris@16 469 for (size_t i = 0; i < numedges; ++i) {
Chris@16 470 edge_props[i] = *ep_iter++;
Chris@16 471 }
Chris@16 472 m_forward.assign_sources_and_targets_global(sources, targets, edge_props, numverts, boost::typed_identity_property_map<vertices_size_type>());
Chris@16 473 }
Chris@16 474
Chris@16 475 // From number of vertices and single-pass range of unsorted edges. Data is
Chris@16 476 // cached in coordinate form before creating the actual graph. Edges are
Chris@16 477 // filtered and transformed for use in a distributed graph.
Chris@16 478 template<typename InputIterator, typename GlobalToLocal, typename SourcePred>
Chris@16 479 compressed_sparse_row_graph(edges_are_unsorted_global_t,
Chris@16 480 InputIterator edge_begin, InputIterator edge_end,
Chris@16 481 vertices_size_type numlocalverts,
Chris@16 482 GlobalToLocal global_to_local,
Chris@16 483 const SourcePred& source_pred,
Chris@16 484 const GraphProperty& prop = GraphProperty())
Chris@16 485 : inherited_vertex_properties(numlocalverts), m_property(prop)
Chris@16 486 {
Chris@16 487 std::vector<vertex_descriptor> sources, targets;
Chris@16 488 boost::graph::detail::split_into_separate_coords_filtered
Chris@16 489 (edge_begin, edge_end, sources, targets, source_pred);
Chris@16 490 m_forward.assign_sources_and_targets_global(sources, targets, numlocalverts, global_to_local);
Chris@16 491 }
Chris@16 492
Chris@16 493 // From number of vertices and single-pass range of unsorted edges and
Chris@16 494 // single-pass range of edge properties. Data is cached in coordinate form
Chris@16 495 // before creating the actual graph. Edges are filtered and transformed for
Chris@16 496 // use in a distributed graph.
Chris@16 497 template<typename InputIterator, typename EdgePropertyIterator,
Chris@16 498 typename GlobalToLocal, typename SourcePred>
Chris@16 499 compressed_sparse_row_graph(edges_are_unsorted_global_t,
Chris@16 500 InputIterator edge_begin, InputIterator edge_end,
Chris@16 501 EdgePropertyIterator ep_iter,
Chris@16 502 vertices_size_type numlocalverts,
Chris@16 503 GlobalToLocal global_to_local,
Chris@16 504 const SourcePred& source_pred,
Chris@16 505 const GraphProperty& prop = GraphProperty())
Chris@16 506 : inherited_vertex_properties(numlocalverts), m_property(prop)
Chris@16 507 {
Chris@16 508 std::vector<vertex_descriptor> sources, targets;
Chris@16 509 std::vector<edge_bundled> edge_props;
Chris@16 510 boost::graph::detail::split_into_separate_coords_filtered
Chris@16 511 (edge_begin, edge_end, ep_iter, sources, targets, edge_props, source_pred);
Chris@16 512 m_forward.assign_sources_and_targets_global(sources, targets, edge_props, numlocalverts, global_to_local);
Chris@16 513 }
Chris@16 514
Chris@16 515
Chris@16 516 // Requires IncidenceGraph and a vertex index map
Chris@16 517 template<typename Graph, typename VertexIndexMap>
Chris@16 518 compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi,
Chris@16 519 vertices_size_type numverts,
Chris@16 520 edges_size_type numedges)
Chris@16 521 : m_property()
Chris@16 522 {
Chris@16 523 assign(g, vi, numverts, numedges);
Chris@16 524 inherited_vertex_properties::resize(numverts);
Chris@16 525 }
Chris@16 526
Chris@16 527 // Requires VertexListGraph and EdgeListGraph
Chris@16 528 template<typename Graph, typename VertexIndexMap>
Chris@16 529 compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi)
Chris@16 530 : m_property()
Chris@16 531 {
Chris@16 532 typename graph_traits<Graph>::edges_size_type numedges = num_edges(g);
Chris@16 533 if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) {
Chris@16 534 numedges *= 2; // Double each edge (actual doubling done by out_edges function)
Chris@16 535 }
Chris@16 536 vertices_size_type numverts = num_vertices(g);
Chris@16 537 assign(g, vi, numverts, numedges);
Chris@16 538 inherited_vertex_properties::resize(numverts);
Chris@16 539 }
Chris@16 540
Chris@16 541 // Requires vertex index map plus requirements of previous constructor
Chris@16 542 template<typename Graph>
Chris@16 543 explicit compressed_sparse_row_graph(const Graph& g)
Chris@16 544 : m_property()
Chris@16 545 {
Chris@16 546 typename graph_traits<Graph>::edges_size_type numedges = num_edges(g);
Chris@16 547 if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) {
Chris@16 548 numedges *= 2; // Double each edge (actual doubling done by out_edges function)
Chris@16 549 }
Chris@16 550 assign(g, get(vertex_index, g), num_vertices(g), numedges);
Chris@16 551 }
Chris@16 552
Chris@16 553 // From any graph (slow and uses a lot of memory)
Chris@16 554 // Requires IncidenceGraph and a vertex index map
Chris@16 555 // Internal helper function
Chris@16 556 // Note that numedges must be doubled for undirected source graphs
Chris@16 557 template<typename Graph, typename VertexIndexMap>
Chris@16 558 void
Chris@16 559 assign(const Graph& g, const VertexIndexMap& vi,
Chris@16 560 vertices_size_type numverts, edges_size_type numedges)
Chris@16 561 {
Chris@16 562 m_forward.assign(g, vi, numverts, numedges);
Chris@16 563 inherited_vertex_properties::resize(numverts);
Chris@16 564 }
Chris@16 565
Chris@16 566 // Requires the above, plus VertexListGraph and EdgeListGraph
Chris@16 567 template<typename Graph, typename VertexIndexMap>
Chris@16 568 void assign(const Graph& g, const VertexIndexMap& vi)
Chris@16 569 {
Chris@16 570 typename graph_traits<Graph>::edges_size_type numedges = num_edges(g);
Chris@16 571 if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) {
Chris@16 572 numedges *= 2; // Double each edge (actual doubling done by out_edges function)
Chris@16 573 }
Chris@16 574 vertices_size_type numverts = num_vertices(g);
Chris@16 575 m_forward.assign(g, vi, numverts, numedges);
Chris@16 576 inherited_vertex_properties::resize(numverts);
Chris@16 577 }
Chris@16 578
Chris@16 579 // Requires the above, plus a vertex_index map.
Chris@16 580 template<typename Graph>
Chris@16 581 void assign(const Graph& g)
Chris@16 582 {
Chris@16 583 typename graph_traits<Graph>::edges_size_type numedges = num_edges(g);
Chris@16 584 if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) {
Chris@16 585 numedges *= 2; // Double each edge (actual doubling done by out_edges function)
Chris@16 586 }
Chris@16 587 vertices_size_type numverts = num_vertices(g);
Chris@16 588 m_forward.assign(g, get(vertex_index, g), numverts, numedges);
Chris@16 589 inherited_vertex_properties::resize(numverts);
Chris@16 590 }
Chris@16 591
Chris@16 592 // Add edges from a sorted (smallest sources first) range of pairs and edge
Chris@16 593 // properties
Chris@16 594 template <typename BidirectionalIteratorOrig, typename EPIterOrig,
Chris@16 595 typename GlobalToLocal>
Chris@16 596 void
Chris@16 597 add_edges_sorted_internal(
Chris@16 598 BidirectionalIteratorOrig first_sorted,
Chris@16 599 BidirectionalIteratorOrig last_sorted,
Chris@16 600 EPIterOrig ep_iter_sorted,
Chris@16 601 const GlobalToLocal& global_to_local) {
Chris@16 602 m_forward.add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted, global_to_local);
Chris@16 603 }
Chris@16 604
Chris@16 605 template <typename BidirectionalIteratorOrig, typename EPIterOrig>
Chris@16 606 void
Chris@16 607 add_edges_sorted_internal(
Chris@16 608 BidirectionalIteratorOrig first_sorted,
Chris@16 609 BidirectionalIteratorOrig last_sorted,
Chris@16 610 EPIterOrig ep_iter_sorted) {
Chris@16 611 m_forward.add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted, typed_identity_property_map<vertices_size_type>());
Chris@16 612 }
Chris@16 613
Chris@16 614 // Add edges from a sorted (smallest sources first) range of pairs
Chris@16 615 template <typename BidirectionalIteratorOrig>
Chris@16 616 void
Chris@16 617 add_edges_sorted_internal(
Chris@16 618 BidirectionalIteratorOrig first_sorted,
Chris@16 619 BidirectionalIteratorOrig last_sorted) {
Chris@16 620 m_forward.add_edges_sorted_internal(first_sorted, last_sorted, detail::default_construct_iterator<edge_bundled>());
Chris@16 621 }
Chris@16 622
Chris@16 623 template <typename BidirectionalIteratorOrig, typename GlobalToLocal>
Chris@16 624 void
Chris@16 625 add_edges_sorted_internal_global(
Chris@16 626 BidirectionalIteratorOrig first_sorted,
Chris@16 627 BidirectionalIteratorOrig last_sorted,
Chris@16 628 const GlobalToLocal& global_to_local) {
Chris@16 629 m_forward.add_edges_sorted_internal(first_sorted, last_sorted, detail::default_construct_iterator<edge_bundled>(), global_to_local);
Chris@16 630 }
Chris@16 631
Chris@16 632 template <typename BidirectionalIteratorOrig, typename EPIterOrig,
Chris@16 633 typename GlobalToLocal>
Chris@16 634 void
Chris@16 635 add_edges_sorted_internal_global(
Chris@16 636 BidirectionalIteratorOrig first_sorted,
Chris@16 637 BidirectionalIteratorOrig last_sorted,
Chris@16 638 EPIterOrig ep_iter_sorted,
Chris@16 639 const GlobalToLocal& global_to_local) {
Chris@16 640 m_forward.add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted, global_to_local);
Chris@16 641 }
Chris@16 642
Chris@16 643 // Add edges from a range of (source, target) pairs that are unsorted
Chris@16 644 template <typename InputIterator, typename GlobalToLocal>
Chris@16 645 inline void
Chris@16 646 add_edges_internal(InputIterator first, InputIterator last,
Chris@16 647 const GlobalToLocal& global_to_local) {
Chris@16 648 typedef compressed_sparse_row_graph Graph;
Chris@16 649 typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_t;
Chris@16 650 typedef std::vector<std::pair<vertex_t, vertex_t> > edge_vector_t;
Chris@16 651 edge_vector_t new_edges(first, last);
Chris@16 652 if (new_edges.empty()) return;
Chris@16 653 std::sort(new_edges.begin(), new_edges.end());
Chris@16 654 this->add_edges_sorted_internal_global(new_edges.begin(), new_edges.end(), global_to_local);
Chris@16 655 }
Chris@16 656
Chris@16 657 template <typename InputIterator>
Chris@16 658 inline void
Chris@16 659 add_edges_internal(InputIterator first, InputIterator last) {
Chris@16 660 this->add_edges_internal(first, last, typed_identity_property_map<vertices_size_type>());
Chris@16 661 }
Chris@16 662
Chris@16 663 // Add edges from a range of (source, target) pairs and edge properties that
Chris@16 664 // are unsorted
Chris@16 665 template <typename InputIterator, typename EPIterator, typename GlobalToLocal>
Chris@16 666 inline void
Chris@16 667 add_edges_internal(InputIterator first, InputIterator last,
Chris@16 668 EPIterator ep_iter, EPIterator ep_iter_end,
Chris@16 669 const GlobalToLocal& global_to_local) {
Chris@16 670 typedef compressed_sparse_row_graph Graph;
Chris@16 671 typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_t;
Chris@16 672 typedef std::pair<vertex_t, vertex_t> vertex_pair;
Chris@16 673 typedef std::vector<
Chris@16 674 boost::tuple<vertex_pair,
Chris@16 675 edge_bundled> >
Chris@16 676 edge_vector_t;
Chris@16 677 edge_vector_t new_edges
Chris@16 678 (boost::make_zip_iterator(boost::make_tuple(first, ep_iter)),
Chris@16 679 boost::make_zip_iterator(boost::make_tuple(last, ep_iter_end)));
Chris@16 680 if (new_edges.empty()) return;
Chris@16 681 std::sort(new_edges.begin(), new_edges.end(),
Chris@16 682 boost::detail::compare_first<
Chris@16 683 std::less<vertex_pair> >());
Chris@16 684 m_forward.add_edges_sorted_internal
Chris@16 685 (boost::make_transform_iterator(
Chris@16 686 new_edges.begin(),
Chris@16 687 boost::detail::my_tuple_get_class<0, vertex_pair>()),
Chris@16 688 boost::make_transform_iterator(
Chris@16 689 new_edges.end(),
Chris@16 690 boost::detail::my_tuple_get_class<0, vertex_pair>()),
Chris@16 691 boost::make_transform_iterator(
Chris@16 692 new_edges.begin(),
Chris@16 693 boost::detail::my_tuple_get_class
Chris@16 694 <1, edge_bundled>()),
Chris@16 695 global_to_local);
Chris@16 696 }
Chris@16 697
Chris@16 698 // Add edges from a range of (source, target) pairs and edge properties that
Chris@16 699 // are unsorted
Chris@16 700 template <typename InputIterator, typename EPIterator>
Chris@16 701 inline void
Chris@16 702 add_edges_internal(InputIterator first, InputIterator last,
Chris@16 703 EPIterator ep_iter, EPIterator ep_iter_end) {
Chris@16 704 this->add_edges_internal(first, last, ep_iter, ep_iter_end, typed_identity_property_map<vertices_size_type>());
Chris@16 705 }
Chris@16 706
Chris@16 707 using inherited_vertex_properties::operator[];
Chris@16 708
Chris@16 709 // Directly access a edge or edge bundle
Chris@16 710 edge_push_back_type& operator[](const edge_descriptor& v)
Chris@16 711 { return m_forward.m_edge_properties[get(edge_index, *this, v)]; }
Chris@16 712
Chris@16 713 const edge_push_back_type& operator[](const edge_descriptor& v) const
Chris@16 714 { return m_forward.m_edge_properties[get(edge_index, *this, v)]; }
Chris@16 715
Chris@16 716 // Directly access a graph bundle
Chris@16 717 graph_bundled& operator[](graph_bundle_t)
Chris@16 718 { return get_property(*this); }
Chris@16 719
Chris@16 720 const graph_bundled& operator[](graph_bundle_t) const
Chris@16 721 { return get_property(*this); }
Chris@16 722
Chris@16 723 // private: non-portable, requires friend templates
Chris@16 724 inherited_vertex_properties& vertex_properties() {return *this;}
Chris@16 725 const inherited_vertex_properties& vertex_properties() const {return *this;}
Chris@16 726 typename forward_type::inherited_edge_properties& edge_properties() { return m_forward; }
Chris@16 727 const typename forward_type::inherited_edge_properties& edge_properties() const { return m_forward; }
Chris@16 728
Chris@16 729 forward_type m_forward;
Chris@16 730 GraphProperty m_property;
Chris@16 731 };
Chris@16 732
Chris@16 733 template<typename VertexProperty,
Chris@16 734 typename EdgeProperty,
Chris@16 735 typename GraphProperty,
Chris@16 736 typename Vertex,
Chris@16 737 typename EdgeIndex>
Chris@16 738 class compressed_sparse_row_graph<bidirectionalS, VertexProperty, EdgeProperty, GraphProperty, Vertex, EdgeIndex>
Chris@16 739 : public detail::indexed_vertex_properties<BOOST_BIDIR_CSR_GRAPH_TYPE,
Chris@16 740 VertexProperty, Vertex, typed_identity_property_map<Vertex> >
Chris@16 741 {
Chris@16 742 public:
Chris@16 743 typedef detail::indexed_vertex_properties<compressed_sparse_row_graph,
Chris@16 744 VertexProperty, Vertex, typed_identity_property_map<Vertex> >
Chris@16 745 inherited_vertex_properties;
Chris@16 746
Chris@16 747 public:
Chris@16 748 // For Property Graph
Chris@16 749 typedef GraphProperty graph_property_type;
Chris@16 750 typedef typename lookup_one_property<GraphProperty, graph_bundle_t>::type graph_bundled;
Chris@16 751 // typedef GraphProperty graph_property_type;
Chris@16 752
Chris@16 753 typedef detail::compressed_sparse_row_structure<EdgeProperty, Vertex, EdgeIndex> forward_type;
Chris@16 754 typedef EdgeIndex /* typename boost::mpl::if_c<boost::is_same<EdgeProperty, boost::no_property>, boost::no_property, EdgeIndex> */ backward_edge_property;
Chris@16 755 typedef detail::compressed_sparse_row_structure<backward_edge_property, Vertex, EdgeIndex> backward_type;
Chris@16 756
Chris@16 757 public:
Chris@16 758 // Concept requirements:
Chris@16 759 // For Graph
Chris@16 760 typedef Vertex vertex_descriptor;
Chris@16 761 typedef detail::csr_edge_descriptor<Vertex, EdgeIndex> edge_descriptor;
Chris@16 762 typedef bidirectional_tag directed_category;
Chris@16 763 typedef allow_parallel_edge_tag edge_parallel_category;
Chris@16 764
Chris@16 765 class traversal_category: public bidirectional_graph_tag,
Chris@16 766 public adjacency_graph_tag,
Chris@16 767 public vertex_list_graph_tag,
Chris@16 768 public edge_list_graph_tag {};
Chris@16 769
Chris@16 770 static vertex_descriptor null_vertex() { return vertex_descriptor(-1); }
Chris@16 771
Chris@16 772 // For VertexListGraph
Chris@16 773 typedef counting_iterator<Vertex> vertex_iterator;
Chris@16 774 typedef Vertex vertices_size_type;
Chris@16 775
Chris@16 776 // For EdgeListGraph
Chris@16 777 typedef EdgeIndex edges_size_type;
Chris@16 778
Chris@16 779 // For IncidenceGraph
Chris@16 780 typedef detail::csr_out_edge_iterator<compressed_sparse_row_graph> out_edge_iterator;
Chris@16 781 typedef EdgeIndex degree_size_type;
Chris@16 782
Chris@16 783 // For AdjacencyGraph
Chris@16 784 typedef typename std::vector<Vertex>::const_iterator adjacency_iterator;
Chris@16 785
Chris@16 786 // For EdgeListGraph
Chris@16 787 typedef detail::csr_edge_iterator<compressed_sparse_row_graph> edge_iterator;
Chris@16 788
Chris@16 789 // For BidirectionalGraph (not implemented)
Chris@16 790 typedef detail::csr_in_edge_iterator<compressed_sparse_row_graph> in_edge_iterator;
Chris@16 791
Chris@16 792 // For internal use
Chris@16 793 typedef csr_graph_tag graph_tag;
Chris@16 794
Chris@16 795 typedef typename forward_type::inherited_edge_properties::edge_bundled edge_bundled;
Chris@16 796 typedef typename forward_type::inherited_edge_properties::edge_push_back_type edge_push_back_type;
Chris@16 797 typedef typename forward_type::inherited_edge_properties::edge_property_type edge_property_type;
Chris@16 798
Chris@16 799 // Constructors
Chris@16 800
Chris@16 801 // Default constructor: an empty graph.
Chris@16 802 compressed_sparse_row_graph(): m_property() {}
Chris@16 803
Chris@16 804 // With numverts vertices
Chris@16 805 compressed_sparse_row_graph(vertices_size_type numverts)
Chris@16 806 : inherited_vertex_properties(numverts),
Chris@16 807 m_forward(numverts), m_backward(numverts) {}
Chris@16 808
Chris@16 809 private:
Chris@16 810
Chris@16 811 void set_up_backward_property_links() {
Chris@16 812 std::pair<edge_iterator, edge_iterator> e = edges(*this);
Chris@16 813 m_backward.assign_unsorted_multi_pass_edges
Chris@16 814 (detail::transpose_edges(
Chris@16 815 detail::make_edge_to_index_pair_iter
Chris@16 816 (*this, get(vertex_index, *this), e.first)),
Chris@16 817 detail::transpose_edges(
Chris@16 818 detail::make_edge_to_index_pair_iter
Chris@16 819 (*this, get(vertex_index, *this), e.second)),
Chris@16 820 boost::counting_iterator<EdgeIndex>(0),
Chris@16 821 m_forward.m_rowstart.size() - 1,
Chris@16 822 typed_identity_property_map<Vertex>(),
Chris@16 823 keep_all());
Chris@16 824 }
Chris@16 825
Chris@16 826 public:
Chris@16 827
Chris@16 828 // From number of vertices and unsorted list of edges
Chris@16 829 template <typename MultiPassInputIterator>
Chris@16 830 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
Chris@16 831 MultiPassInputIterator edge_begin,
Chris@16 832 MultiPassInputIterator edge_end,
Chris@16 833 vertices_size_type numverts,
Chris@16 834 const GraphProperty& prop = GraphProperty())
Chris@16 835 : inherited_vertex_properties(numverts), m_property(prop)
Chris@16 836 {
Chris@16 837 m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, numverts, typed_identity_property_map<Vertex>(), keep_all());
Chris@16 838 set_up_backward_property_links();
Chris@16 839 }
Chris@16 840
Chris@16 841 // From number of vertices and unsorted list of edges, plus edge properties
Chris@16 842 template <typename MultiPassInputIterator, typename EdgePropertyIterator>
Chris@16 843 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
Chris@16 844 MultiPassInputIterator edge_begin,
Chris@16 845 MultiPassInputIterator edge_end,
Chris@16 846 EdgePropertyIterator ep_iter,
Chris@16 847 vertices_size_type numverts,
Chris@16 848 const GraphProperty& prop = GraphProperty())
Chris@16 849 : inherited_vertex_properties(numverts), m_forward(), m_property(prop)
Chris@16 850 {
Chris@16 851 m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, ep_iter, numverts, typed_identity_property_map<Vertex>(), keep_all());
Chris@16 852 set_up_backward_property_links();
Chris@16 853 }
Chris@16 854
Chris@16 855 // From number of vertices and unsorted list of edges, with filter and
Chris@16 856 // global-to-local map
Chris@16 857 template <typename MultiPassInputIterator, typename GlobalToLocal, typename SourcePred>
Chris@16 858 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t,
Chris@16 859 MultiPassInputIterator edge_begin,
Chris@16 860 MultiPassInputIterator edge_end,
Chris@16 861 vertices_size_type numlocalverts,
Chris@16 862 const GlobalToLocal& global_to_local,
Chris@16 863 const SourcePred& source_pred,
Chris@16 864 const GraphProperty& prop = GraphProperty())
Chris@16 865 : inherited_vertex_properties(numlocalverts), m_forward(), m_property(prop)
Chris@16 866 {
Chris@16 867 m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, numlocalverts, global_to_local, source_pred);
Chris@16 868 set_up_backward_property_links();
Chris@16 869 }
Chris@16 870
Chris@16 871 // From number of vertices and unsorted list of edges, plus edge properties,
Chris@16 872 // with filter and global-to-local map
Chris@16 873 template <typename MultiPassInputIterator, typename EdgePropertyIterator, typename GlobalToLocal, typename SourcePred>
Chris@16 874 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t,
Chris@16 875 MultiPassInputIterator edge_begin,
Chris@16 876 MultiPassInputIterator edge_end,
Chris@16 877 EdgePropertyIterator ep_iter,
Chris@16 878 vertices_size_type numlocalverts,
Chris@16 879 const GlobalToLocal& global_to_local,
Chris@16 880 const SourcePred& source_pred,
Chris@16 881 const GraphProperty& prop = GraphProperty())
Chris@16 882 : inherited_vertex_properties(numlocalverts), m_forward(), m_property(prop)
Chris@16 883 {
Chris@16 884 m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, ep_iter, numlocalverts, global_to_local, source_pred);
Chris@16 885 set_up_backward_property_links();
Chris@16 886 }
Chris@16 887
Chris@16 888 // Requires IncidenceGraph and a vertex index map
Chris@16 889 template<typename Graph, typename VertexIndexMap>
Chris@16 890 compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi,
Chris@16 891 vertices_size_type numverts,
Chris@16 892 edges_size_type numedges)
Chris@16 893 : m_property()
Chris@16 894 {
Chris@16 895 assign(g, vi, numverts, numedges);
Chris@16 896 inherited_vertex_properties::resize(numverts);
Chris@16 897 }
Chris@16 898
Chris@16 899 // Requires VertexListGraph and EdgeListGraph
Chris@16 900 template<typename Graph, typename VertexIndexMap>
Chris@16 901 compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi)
Chris@16 902 : m_property()
Chris@16 903 {
Chris@16 904 typename graph_traits<Graph>::edges_size_type numedges = num_edges(g);
Chris@16 905 if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) {
Chris@16 906 numedges *= 2; // Double each edge (actual doubling done by out_edges function)
Chris@16 907 }
Chris@16 908 vertices_size_type numverts = num_vertices(g);
Chris@16 909 assign(g, vi, numverts, numedges);
Chris@16 910 inherited_vertex_properties::resize(numverts);
Chris@16 911 }
Chris@16 912
Chris@16 913 // Requires vertex index map plus requirements of previous constructor
Chris@16 914 template<typename Graph>
Chris@16 915 explicit compressed_sparse_row_graph(const Graph& g)
Chris@16 916 : m_property()
Chris@16 917 {
Chris@16 918 typename graph_traits<Graph>::edges_size_type numedges = num_edges(g);
Chris@16 919 if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) {
Chris@16 920 numedges *= 2; // Double each edge (actual doubling done by out_edges function)
Chris@16 921 }
Chris@16 922 assign(g, get(vertex_index, g), num_vertices(g), numedges);
Chris@16 923 }
Chris@16 924
Chris@16 925 // From any graph (slow and uses a lot of memory)
Chris@16 926 // Requires IncidenceGraph and a vertex index map
Chris@16 927 // Internal helper function
Chris@16 928 // Note that numedges must be doubled for undirected source graphs
Chris@16 929 template<typename Graph, typename VertexIndexMap>
Chris@16 930 void
Chris@16 931 assign(const Graph& g, const VertexIndexMap& vi,
Chris@16 932 vertices_size_type numverts, edges_size_type numedges)
Chris@16 933 {
Chris@16 934 m_forward.assign(g, vi, numverts, numedges);
Chris@16 935 inherited_vertex_properties::resize(numverts);
Chris@16 936 set_up_backward_property_links();
Chris@16 937 }
Chris@16 938
Chris@16 939 // Requires the above, plus VertexListGraph and EdgeListGraph
Chris@16 940 template<typename Graph, typename VertexIndexMap>
Chris@16 941 void assign(const Graph& g, const VertexIndexMap& vi)
Chris@16 942 {
Chris@16 943 typename graph_traits<Graph>::edges_size_type numedges = num_edges(g);
Chris@16 944 if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) {
Chris@16 945 numedges *= 2; // Double each edge (actual doubling done by out_edges function)
Chris@16 946 }
Chris@16 947 vertices_size_type numverts = num_vertices(g);
Chris@16 948 m_forward.assign(g, vi, numverts, numedges);
Chris@16 949 inherited_vertex_properties::resize(numverts);
Chris@16 950 set_up_backward_property_links();
Chris@16 951 }
Chris@16 952
Chris@16 953 // Requires the above, plus a vertex_index map.
Chris@16 954 template<typename Graph>
Chris@16 955 void assign(const Graph& g)
Chris@16 956 {
Chris@16 957 typename graph_traits<Graph>::edges_size_type numedges = num_edges(g);
Chris@16 958 if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) {
Chris@16 959 numedges *= 2; // Double each edge (actual doubling done by out_edges function)
Chris@16 960 }
Chris@16 961 vertices_size_type numverts = num_vertices(g);
Chris@16 962 m_forward.assign(g, get(vertex_index, g), numverts, numedges);
Chris@16 963 inherited_vertex_properties::resize(numverts);
Chris@16 964 set_up_backward_property_links();
Chris@16 965 }
Chris@16 966
Chris@16 967 using inherited_vertex_properties::operator[];
Chris@16 968
Chris@16 969 // Directly access a edge or edge bundle
Chris@16 970 edge_push_back_type& operator[](const edge_descriptor& v)
Chris@16 971 { return m_forward.m_edge_properties[get(edge_index, *this, v)]; }
Chris@16 972
Chris@16 973 const edge_push_back_type& operator[](const edge_descriptor& v) const
Chris@16 974 { return m_forward.m_edge_properties[get(edge_index, *this, v)]; }
Chris@16 975
Chris@16 976 // private: non-portable, requires friend templates
Chris@16 977 inherited_vertex_properties& vertex_properties() {return *this;}
Chris@16 978 const inherited_vertex_properties& vertex_properties() const {return *this;}
Chris@16 979 typename forward_type::inherited_edge_properties& edge_properties() { return m_forward; }
Chris@16 980 const typename forward_type::inherited_edge_properties& edge_properties() const { return m_forward; }
Chris@16 981
Chris@16 982 forward_type m_forward;
Chris@16 983 backward_type m_backward;
Chris@16 984 GraphProperty m_property;
Chris@16 985 };
Chris@16 986
Chris@16 987 // Construction functions
Chris@16 988 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 989 inline Vertex
Chris@16 990 add_vertex(BOOST_CSR_GRAPH_TYPE& g) {
Chris@16 991 add_vertex(g, typename BOOST_CSR_GRAPH_TYPE::vertex_bundled());
Chris@16 992 }
Chris@16 993
Chris@16 994 template<BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 995 inline Vertex
Chris@16 996 add_vertex(BOOST_DIR_CSR_GRAPH_TYPE& g,
Chris@16 997 typename BOOST_DIR_CSR_GRAPH_TYPE::vertex_bundled const& p) {
Chris@16 998 Vertex old_num_verts_plus_one = g.m_forward.m_rowstart.size();
Chris@16 999 g.m_forward.m_rowstart.push_back(g.m_forward.m_rowstart.back());
Chris@16 1000 g.vertex_properties().push_back(p);
Chris@16 1001 return old_num_verts_plus_one - 1;
Chris@16 1002 }
Chris@16 1003
Chris@16 1004 template<BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1005 inline Vertex
Chris@16 1006 add_vertex(BOOST_BIDIR_CSR_GRAPH_TYPE& g,
Chris@16 1007 typename BOOST_BIDIR_CSR_GRAPH_TYPE::vertex_bundled const& p) {
Chris@16 1008 Vertex old_num_verts_plus_one = g.m_forward.m_rowstart.size();
Chris@16 1009 g.m_forward.m_rowstart.push_back(g.m_forward.m_rowstart.back());
Chris@16 1010 g.m_backward.m_rowstart.push_back(g.m_backward.m_rowstart.back());
Chris@16 1011 g.vertex_properties().push_back(p);
Chris@16 1012 return old_num_verts_plus_one - 1;
Chris@16 1013 }
Chris@16 1014
Chris@16 1015 template<BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1016 inline Vertex
Chris@16 1017 add_vertices(typename BOOST_DIR_CSR_GRAPH_TYPE::vertices_size_type count, BOOST_DIR_CSR_GRAPH_TYPE& g) {
Chris@16 1018 Vertex old_num_verts_plus_one = g.m_forward.m_rowstart.size();
Chris@16 1019 EdgeIndex numedges = g.m_forward.m_rowstart.back();
Chris@16 1020 g.m_forward.m_rowstart.resize(old_num_verts_plus_one + count, numedges);
Chris@16 1021 g.vertex_properties().resize(num_vertices(g));
Chris@16 1022 return old_num_verts_plus_one - 1;
Chris@16 1023 }
Chris@16 1024
Chris@16 1025 // Add edges from a sorted (smallest sources first) range of pairs and edge
Chris@16 1026 // properties
Chris@16 1027 template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename BidirectionalIteratorOrig,
Chris@16 1028 typename EPIterOrig>
Chris@16 1029 void
Chris@16 1030 add_edges_sorted(
Chris@16 1031 BidirectionalIteratorOrig first_sorted,
Chris@16 1032 BidirectionalIteratorOrig last_sorted,
Chris@16 1033 EPIterOrig ep_iter_sorted,
Chris@16 1034 BOOST_DIR_CSR_GRAPH_TYPE& g) {
Chris@16 1035 g.add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted);
Chris@16 1036 }
Chris@16 1037
Chris@16 1038 // Add edges from a sorted (smallest sources first) range of pairs
Chris@16 1039 template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename BidirectionalIteratorOrig>
Chris@16 1040 void
Chris@16 1041 add_edges_sorted(
Chris@16 1042 BidirectionalIteratorOrig first_sorted,
Chris@16 1043 BidirectionalIteratorOrig last_sorted,
Chris@16 1044 BOOST_DIR_CSR_GRAPH_TYPE& g) {
Chris@16 1045 g.add_edges_sorted_internal(first_sorted, last_sorted);
Chris@16 1046 }
Chris@16 1047
Chris@16 1048 template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename BidirectionalIteratorOrig,
Chris@16 1049 typename EPIterOrig, typename GlobalToLocal>
Chris@16 1050 void
Chris@16 1051 add_edges_sorted_global(
Chris@16 1052 BidirectionalIteratorOrig first_sorted,
Chris@16 1053 BidirectionalIteratorOrig last_sorted,
Chris@16 1054 EPIterOrig ep_iter_sorted,
Chris@16 1055 const GlobalToLocal& global_to_local,
Chris@16 1056 BOOST_DIR_CSR_GRAPH_TYPE& g) {
Chris@16 1057 g.add_edges_sorted_internal_global(first_sorted, last_sorted, ep_iter_sorted,
Chris@16 1058 global_to_local);
Chris@16 1059 }
Chris@16 1060
Chris@16 1061 // Add edges from a sorted (smallest sources first) range of pairs
Chris@16 1062 template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename BidirectionalIteratorOrig,
Chris@16 1063 typename GlobalToLocal>
Chris@16 1064 void
Chris@16 1065 add_edges_sorted_global(
Chris@16 1066 BidirectionalIteratorOrig first_sorted,
Chris@16 1067 BidirectionalIteratorOrig last_sorted,
Chris@16 1068 const GlobalToLocal& global_to_local,
Chris@16 1069 BOOST_DIR_CSR_GRAPH_TYPE& g) {
Chris@16 1070 g.add_edges_sorted_internal_global(first_sorted, last_sorted, global_to_local);
Chris@16 1071 }
Chris@16 1072
Chris@16 1073 // Add edges from a range of (source, target) pairs that are unsorted
Chris@16 1074 template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator,
Chris@16 1075 typename GlobalToLocal>
Chris@16 1076 inline void
Chris@16 1077 add_edges_global(InputIterator first, InputIterator last,
Chris@16 1078 const GlobalToLocal& global_to_local, BOOST_DIR_CSR_GRAPH_TYPE& g) {
Chris@16 1079 g.add_edges_internal(first, last, global_to_local);
Chris@16 1080 }
Chris@16 1081
Chris@16 1082 // Add edges from a range of (source, target) pairs that are unsorted
Chris@16 1083 template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator>
Chris@16 1084 inline void
Chris@16 1085 add_edges(InputIterator first, InputIterator last, BOOST_DIR_CSR_GRAPH_TYPE& g) {
Chris@16 1086 g.add_edges_internal(first, last);
Chris@16 1087 }
Chris@16 1088
Chris@16 1089 // Add edges from a range of (source, target) pairs and edge properties that
Chris@16 1090 // are unsorted
Chris@16 1091 template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS,
Chris@16 1092 typename InputIterator, typename EPIterator>
Chris@16 1093 inline void
Chris@16 1094 add_edges(InputIterator first, InputIterator last,
Chris@16 1095 EPIterator ep_iter, EPIterator ep_iter_end,
Chris@16 1096 BOOST_DIR_CSR_GRAPH_TYPE& g) {
Chris@16 1097 g.add_edges_internal(first, last, ep_iter, ep_iter_end);
Chris@16 1098 }
Chris@16 1099
Chris@16 1100 template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS,
Chris@16 1101 typename InputIterator, typename EPIterator, typename GlobalToLocal>
Chris@16 1102 inline void
Chris@16 1103 add_edges_global(InputIterator first, InputIterator last,
Chris@16 1104 EPIterator ep_iter, EPIterator ep_iter_end,
Chris@16 1105 const GlobalToLocal& global_to_local,
Chris@16 1106 BOOST_DIR_CSR_GRAPH_TYPE& g) {
Chris@16 1107 g.add_edges_internal(first, last, ep_iter, ep_iter_end, global_to_local);
Chris@16 1108 }
Chris@16 1109
Chris@16 1110 // From VertexListGraph
Chris@16 1111 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1112 inline Vertex
Chris@16 1113 num_vertices(const BOOST_CSR_GRAPH_TYPE& g) {
Chris@16 1114 return g.m_forward.m_rowstart.size() - 1;
Chris@16 1115 }
Chris@16 1116
Chris@16 1117 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1118 std::pair<counting_iterator<Vertex>, counting_iterator<Vertex> >
Chris@16 1119 inline vertices(const BOOST_CSR_GRAPH_TYPE& g) {
Chris@16 1120 return std::make_pair(counting_iterator<Vertex>(0),
Chris@16 1121 counting_iterator<Vertex>(num_vertices(g)));
Chris@16 1122 }
Chris@16 1123
Chris@16 1124 // From IncidenceGraph
Chris@16 1125 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1126 inline Vertex
Chris@16 1127 source(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e,
Chris@16 1128 const BOOST_CSR_GRAPH_TYPE&)
Chris@16 1129 {
Chris@16 1130 return e.src;
Chris@16 1131 }
Chris@16 1132
Chris@16 1133 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1134 inline Vertex
Chris@16 1135 target(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e,
Chris@16 1136 const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1137 {
Chris@16 1138 return g.m_forward.m_column[e.idx];
Chris@16 1139 }
Chris@16 1140
Chris@16 1141 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1142 inline std::pair<typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator,
Chris@16 1143 typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator>
Chris@16 1144 out_edges(Vertex v, const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1145 {
Chris@16 1146 typedef typename BOOST_CSR_GRAPH_TYPE::edge_descriptor ed;
Chris@16 1147 typedef typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator it;
Chris@16 1148 EdgeIndex v_row_start = g.m_forward.m_rowstart[v];
Chris@16 1149 EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1];
Chris@16 1150 return std::make_pair(it(ed(v, v_row_start)),
Chris@16 1151 it(ed(v, next_row_start)));
Chris@16 1152 }
Chris@16 1153
Chris@16 1154 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1155 inline EdgeIndex
Chris@16 1156 out_degree(Vertex v, const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1157 {
Chris@16 1158 EdgeIndex v_row_start = g.m_forward.m_rowstart[v];
Chris@16 1159 EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1];
Chris@16 1160 return next_row_start - v_row_start;
Chris@16 1161 }
Chris@16 1162
Chris@16 1163 template<BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1164 inline std::pair<typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator,
Chris@16 1165 typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator>
Chris@16 1166 in_edges(Vertex v, const BOOST_BIDIR_CSR_GRAPH_TYPE& g)
Chris@16 1167 {
Chris@16 1168 typedef typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator it;
Chris@16 1169 EdgeIndex v_row_start = g.m_backward.m_rowstart[v];
Chris@16 1170 EdgeIndex next_row_start = g.m_backward.m_rowstart[v + 1];
Chris@16 1171 return std::make_pair(it(g, v_row_start),
Chris@16 1172 it(g, next_row_start));
Chris@16 1173 }
Chris@16 1174
Chris@16 1175 template<BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1176 inline EdgeIndex
Chris@16 1177 in_degree(Vertex v, const BOOST_BIDIR_CSR_GRAPH_TYPE& g)
Chris@16 1178 {
Chris@16 1179 EdgeIndex v_row_start = g.m_backward.m_rowstart[v];
Chris@16 1180 EdgeIndex next_row_start = g.m_backward.m_rowstart[v + 1];
Chris@16 1181 return next_row_start - v_row_start;
Chris@16 1182 }
Chris@16 1183
Chris@16 1184 // From AdjacencyGraph
Chris@16 1185 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1186 inline std::pair<typename BOOST_CSR_GRAPH_TYPE::adjacency_iterator,
Chris@16 1187 typename BOOST_CSR_GRAPH_TYPE::adjacency_iterator>
Chris@16 1188 adjacent_vertices(Vertex v, const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1189 {
Chris@16 1190 EdgeIndex v_row_start = g.m_forward.m_rowstart[v];
Chris@16 1191 EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1];
Chris@16 1192 return std::make_pair(g.m_forward.m_column.begin() + v_row_start,
Chris@16 1193 g.m_forward.m_column.begin() + next_row_start);
Chris@16 1194 }
Chris@16 1195
Chris@16 1196 // Extra, common functions
Chris@16 1197 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1198 inline typename graph_traits<BOOST_CSR_GRAPH_TYPE>::vertex_descriptor
Chris@16 1199 vertex(typename graph_traits<BOOST_CSR_GRAPH_TYPE>::vertex_descriptor i,
Chris@16 1200 const BOOST_CSR_GRAPH_TYPE&)
Chris@16 1201 {
Chris@16 1202 return i;
Chris@16 1203 }
Chris@16 1204
Chris@16 1205 // edge() can be provided in linear time for the new interface
Chris@16 1206
Chris@16 1207 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1208 inline std::pair<typename BOOST_CSR_GRAPH_TYPE::edge_descriptor, bool>
Chris@16 1209 edge(Vertex i, Vertex j, const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1210 {
Chris@16 1211 typedef typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator out_edge_iter;
Chris@16 1212 std::pair<out_edge_iter, out_edge_iter> range = out_edges(i, g);
Chris@16 1213 for (; range.first != range.second; ++range.first) {
Chris@16 1214 if (target(*range.first, g) == j)
Chris@16 1215 return std::make_pair(*range.first, true);
Chris@16 1216 }
Chris@16 1217 return std::make_pair(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor(),
Chris@16 1218 false);
Chris@16 1219 }
Chris@16 1220
Chris@16 1221 // Find an edge given its index in the graph
Chris@16 1222 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1223 inline typename BOOST_CSR_GRAPH_TYPE::edge_descriptor
Chris@16 1224 edge_from_index(EdgeIndex idx, const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1225 {
Chris@16 1226 typedef typename std::vector<EdgeIndex>::const_iterator row_start_iter;
Chris@16 1227 BOOST_ASSERT (idx < num_edges(g));
Chris@16 1228 row_start_iter src_plus_1 =
Chris@16 1229 std::upper_bound(g.m_forward.m_rowstart.begin(),
Chris@16 1230 g.m_forward.m_rowstart.end(),
Chris@16 1231 idx);
Chris@16 1232 // Get last source whose rowstart is at most idx
Chris@16 1233 // upper_bound returns this position plus 1
Chris@16 1234 Vertex src = (src_plus_1 - g.m_forward.m_rowstart.begin()) - 1;
Chris@16 1235 return typename BOOST_CSR_GRAPH_TYPE::edge_descriptor(src, idx);
Chris@16 1236 }
Chris@16 1237
Chris@16 1238 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1239 inline EdgeIndex
Chris@16 1240 num_edges(const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1241 {
Chris@16 1242 return g.m_forward.m_column.size();
Chris@16 1243 }
Chris@16 1244
Chris@16 1245 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1246 std::pair<typename BOOST_CSR_GRAPH_TYPE::edge_iterator,
Chris@16 1247 typename BOOST_CSR_GRAPH_TYPE::edge_iterator>
Chris@16 1248 edges(const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1249 {
Chris@16 1250 typedef typename BOOST_CSR_GRAPH_TYPE::edge_iterator ei;
Chris@16 1251 typedef typename BOOST_CSR_GRAPH_TYPE::edge_descriptor edgedesc;
Chris@16 1252 if (g.m_forward.m_rowstart.size() == 1 || g.m_forward.m_column.empty()) {
Chris@16 1253 return std::make_pair(ei(), ei());
Chris@16 1254 } else {
Chris@16 1255 // Find the first vertex that has outgoing edges
Chris@16 1256 Vertex src = 0;
Chris@16 1257 while (g.m_forward.m_rowstart[src + 1] == 0) ++src;
Chris@16 1258 return std::make_pair(ei(g, edgedesc(src, 0), g.m_forward.m_rowstart[src + 1]),
Chris@16 1259 ei(g, edgedesc(num_vertices(g), g.m_forward.m_column.size()), 0));
Chris@16 1260 }
Chris@16 1261 }
Chris@16 1262
Chris@16 1263 // For Property Graph
Chris@16 1264
Chris@16 1265 // Graph properties
Chris@16 1266 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS, class Tag, class Value>
Chris@16 1267 inline void
Chris@16 1268 set_property(BOOST_CSR_GRAPH_TYPE& g, Tag tag, const Value& value)
Chris@16 1269 {
Chris@16 1270 get_property_value(g.m_property, tag) = value;
Chris@16 1271 }
Chris@16 1272
Chris@16 1273 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS, class Tag>
Chris@16 1274 inline
Chris@16 1275 typename graph_property<BOOST_CSR_GRAPH_TYPE, Tag>::type&
Chris@16 1276 get_property(BOOST_CSR_GRAPH_TYPE& g, Tag tag)
Chris@16 1277 {
Chris@16 1278 return get_property_value(g.m_property, tag);
Chris@16 1279 }
Chris@16 1280
Chris@16 1281 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS, class Tag>
Chris@16 1282 inline
Chris@16 1283 const
Chris@16 1284 typename graph_property<BOOST_CSR_GRAPH_TYPE, Tag>::type&
Chris@16 1285 get_property(const BOOST_CSR_GRAPH_TYPE& g, Tag tag)
Chris@16 1286 {
Chris@16 1287 return get_property_value(g.m_property, tag);
Chris@16 1288 }
Chris@16 1289
Chris@16 1290 template <typename G, typename Tag, typename Kind>
Chris@16 1291 struct csr_property_map_helper {};
Chris@16 1292 // Kind == void for invalid property tags, so we can use that to SFINAE out
Chris@16 1293
Chris@16 1294 template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
Chris@16 1295 struct csr_property_map_helper<BOOST_CSR_GRAPH_TYPE, Tag, vertex_property_tag> {
Chris@16 1296 typedef vertex_all_t all_tag;
Chris@16 1297 typedef typename property_traits<typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::type>::key_type key_type;
Chris@16 1298 typedef VertexProperty plist_type;
Chris@16 1299 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::type all_type;
Chris@16 1300 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::const_type all_const_type;
Chris@16 1301 typedef transform_value_property_map<detail::lookup_one_property_f<plist_type, Tag>, all_type> type;
Chris@16 1302 typedef transform_value_property_map<detail::lookup_one_property_f<const plist_type, Tag>, all_const_type> const_type;
Chris@16 1303 };
Chris@16 1304
Chris@16 1305 template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
Chris@16 1306 struct csr_property_map_helper<BOOST_CSR_GRAPH_TYPE, Tag, edge_property_tag> {
Chris@16 1307 typedef edge_all_t all_tag;
Chris@16 1308 typedef typename property_traits<typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::type>::key_type key_type;
Chris@16 1309 typedef EdgeProperty plist_type;
Chris@16 1310 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::type all_type;
Chris@16 1311 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::const_type all_const_type;
Chris@16 1312 typedef transform_value_property_map<detail::lookup_one_property_f<plist_type, Tag>, all_type> type;
Chris@16 1313 typedef transform_value_property_map<detail::lookup_one_property_f<const plist_type, Tag>, all_const_type> const_type;
Chris@16 1314 };
Chris@16 1315
Chris@16 1316 template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
Chris@16 1317 struct csr_property_map_helper<BOOST_CSR_GRAPH_TYPE, Tag, graph_property_tag> {
Chris@16 1318 typedef graph_all_t all_tag;
Chris@16 1319 typedef BOOST_CSR_GRAPH_TYPE* key_type;
Chris@16 1320 typedef GraphProperty plist_type;
Chris@16 1321 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::type all_type;
Chris@16 1322 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::const_type all_const_type;
Chris@16 1323 typedef transform_value_property_map<detail::lookup_one_property_f<plist_type, Tag>, all_type> type;
Chris@16 1324 typedef transform_value_property_map<detail::lookup_one_property_f<const plist_type, Tag>, all_const_type> const_type;
Chris@16 1325 };
Chris@16 1326
Chris@16 1327 // disable_if isn't truly necessary but required to avoid ambiguity with specializations below
Chris@16 1328 template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
Chris@16 1329 struct property_map<BOOST_CSR_GRAPH_TYPE, Tag, typename disable_if<detail::is_distributed_selector<Vertex> >::type>:
Chris@16 1330 csr_property_map_helper<
Chris@16 1331 BOOST_CSR_GRAPH_TYPE,
Chris@16 1332 Tag,
Chris@16 1333 typename detail::property_kind_from_graph<BOOST_CSR_GRAPH_TYPE, Tag>
Chris@16 1334 ::type> {};
Chris@16 1335
Chris@16 1336 template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
Chris@16 1337 typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::type
Chris@16 1338 get(Tag tag, BOOST_CSR_GRAPH_TYPE& g) {
Chris@16 1339 return typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::type(tag, get(typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag(), g));
Chris@16 1340 }
Chris@16 1341
Chris@16 1342 template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
Chris@16 1343 typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::const_type
Chris@16 1344 get(Tag tag, const BOOST_CSR_GRAPH_TYPE& g) {
Chris@16 1345 return typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::const_type(tag, get(typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag(), g));
Chris@16 1346 }
Chris@16 1347
Chris@16 1348 template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
Chris@16 1349 typename property_traits<typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::type>::reference
Chris@16 1350 get(Tag tag, BOOST_CSR_GRAPH_TYPE& g, typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::key_type k) {
Chris@16 1351 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag all_tag;
Chris@16 1352 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, all_tag>::type outer_pm;
Chris@16 1353 return lookup_one_property<typename property_traits<outer_pm>::value_type, Tag>::lookup(get(all_tag(), g, k), tag);
Chris@16 1354 }
Chris@16 1355
Chris@16 1356 template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
Chris@16 1357 typename property_traits<typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::const_type>::reference
Chris@16 1358 get(Tag tag, const BOOST_CSR_GRAPH_TYPE& g, typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::key_type k) {
Chris@16 1359 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag all_tag;
Chris@16 1360 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, all_tag>::const_type outer_pm;
Chris@16 1361 return lookup_one_property<const typename property_traits<outer_pm>::value_type, Tag>::lookup(get(all_tag(), g, k), tag);
Chris@16 1362 }
Chris@16 1363
Chris@16 1364 template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
Chris@16 1365 void
Chris@16 1366 put(Tag tag,
Chris@16 1367 BOOST_CSR_GRAPH_TYPE& g,
Chris@16 1368 typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::key_type k,
Chris@16 1369 typename lookup_one_property<typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::plist_type, Tag>::type val) {
Chris@16 1370 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag all_tag;
Chris@16 1371 lookup_one_property<typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::plist_type, Tag>::lookup(get(all_tag(), g, k), tag) = val;
Chris@16 1372 }
Chris@16 1373
Chris@16 1374 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1375 struct property_map<BOOST_CSR_GRAPH_TYPE, vertex_index_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type>
Chris@16 1376 {
Chris@16 1377 typedef typed_identity_property_map<Vertex> type;
Chris@16 1378 typedef type const_type;
Chris@16 1379 };
Chris@16 1380
Chris@16 1381 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1382 struct property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type>
Chris@16 1383 {
Chris@16 1384 typedef detail::csr_edge_index_map<Vertex, EdgeIndex> type;
Chris@16 1385 typedef type const_type;
Chris@16 1386 };
Chris@16 1387
Chris@16 1388 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1389 struct property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type>
Chris@16 1390 {
Chris@16 1391 typedef typename BOOST_CSR_GRAPH_TYPE::inherited_vertex_properties::vertex_map_type type;
Chris@16 1392 typedef typename BOOST_CSR_GRAPH_TYPE::inherited_vertex_properties::const_vertex_map_type const_type;
Chris@16 1393 };
Chris@16 1394
Chris@16 1395 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1396 struct property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type>
Chris@16 1397 {
Chris@16 1398 typedef typename BOOST_CSR_GRAPH_TYPE::forward_type::inherited_edge_properties::edge_map_type type;
Chris@16 1399 typedef typename BOOST_CSR_GRAPH_TYPE::forward_type::inherited_edge_properties::const_edge_map_type const_type;
Chris@16 1400 };
Chris@16 1401
Chris@16 1402 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1403 struct property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type>
Chris@16 1404 {
Chris@16 1405 typedef boost::ref_property_map<BOOST_CSR_GRAPH_TYPE*, typename BOOST_CSR_GRAPH_TYPE::graph_property_type> type;
Chris@16 1406 typedef boost::ref_property_map<BOOST_CSR_GRAPH_TYPE*, const typename BOOST_CSR_GRAPH_TYPE::graph_property_type> const_type;
Chris@16 1407 };
Chris@16 1408
Chris@16 1409 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1410 inline typed_identity_property_map<Vertex>
Chris@16 1411 get(vertex_index_t, const BOOST_CSR_GRAPH_TYPE&)
Chris@16 1412 {
Chris@16 1413 return typed_identity_property_map<Vertex>();
Chris@16 1414 }
Chris@16 1415
Chris@16 1416 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1417 inline Vertex
Chris@16 1418 get(vertex_index_t,
Chris@16 1419 const BOOST_CSR_GRAPH_TYPE&, Vertex v)
Chris@16 1420 {
Chris@16 1421 return v;
Chris@16 1422 }
Chris@16 1423
Chris@16 1424 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1425 inline typed_identity_property_map<Vertex>
Chris@16 1426 get(vertex_index_t, BOOST_CSR_GRAPH_TYPE&)
Chris@16 1427 {
Chris@16 1428 return typed_identity_property_map<Vertex>();
Chris@16 1429 }
Chris@16 1430
Chris@16 1431 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1432 inline Vertex
Chris@16 1433 get(vertex_index_t,
Chris@16 1434 BOOST_CSR_GRAPH_TYPE&, Vertex v)
Chris@16 1435 {
Chris@16 1436 return v;
Chris@16 1437 }
Chris@16 1438
Chris@16 1439 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1440 inline typename property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t>::const_type
Chris@16 1441 get(edge_index_t, const BOOST_CSR_GRAPH_TYPE&)
Chris@16 1442 {
Chris@16 1443 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t>::const_type
Chris@16 1444 result_type;
Chris@16 1445 return result_type();
Chris@16 1446 }
Chris@16 1447
Chris@16 1448 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1449 inline EdgeIndex
Chris@16 1450 get(edge_index_t, const BOOST_CSR_GRAPH_TYPE&,
Chris@16 1451 typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e)
Chris@16 1452 {
Chris@16 1453 return e.idx;
Chris@16 1454 }
Chris@16 1455
Chris@16 1456 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1457 inline typename property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t>::const_type
Chris@16 1458 get(edge_index_t, BOOST_CSR_GRAPH_TYPE&)
Chris@16 1459 {
Chris@16 1460 typedef typename property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t>::const_type
Chris@16 1461 result_type;
Chris@16 1462 return result_type();
Chris@16 1463 }
Chris@16 1464
Chris@16 1465 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1466 inline EdgeIndex
Chris@16 1467 get(edge_index_t, BOOST_CSR_GRAPH_TYPE&,
Chris@16 1468 typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e)
Chris@16 1469 {
Chris@16 1470 return e.idx;
Chris@16 1471 }
Chris@16 1472
Chris@16 1473 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1474 inline typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::type
Chris@16 1475 get(vertex_all_t, BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1476 {
Chris@16 1477 return g.get_vertex_bundle(get(vertex_index, g));
Chris@16 1478 }
Chris@16 1479
Chris@16 1480 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1481 inline typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::const_type
Chris@16 1482 get(vertex_all_t, const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1483 {
Chris@16 1484 return g.get_vertex_bundle(get(vertex_index, g));
Chris@16 1485 }
Chris@16 1486
Chris@16 1487 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1488 inline VertexProperty&
Chris@16 1489 get(vertex_all_t,
Chris@16 1490 BOOST_CSR_GRAPH_TYPE& g, Vertex v)
Chris@16 1491 {
Chris@16 1492 return get(vertex_all, g)[v];
Chris@16 1493 }
Chris@16 1494
Chris@16 1495 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1496 inline const VertexProperty&
Chris@16 1497 get(vertex_all_t,
Chris@16 1498 const BOOST_CSR_GRAPH_TYPE& g, Vertex v)
Chris@16 1499 {
Chris@16 1500 return get(vertex_all, g)[v];
Chris@16 1501 }
Chris@16 1502
Chris@16 1503 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1504 inline void
Chris@16 1505 put(vertex_all_t,
Chris@16 1506 BOOST_CSR_GRAPH_TYPE& g,
Chris@16 1507 Vertex v,
Chris@16 1508 const VertexProperty& val)
Chris@16 1509 {
Chris@16 1510 put(get(vertex_all, g), v, val);
Chris@16 1511 }
Chris@16 1512
Chris@16 1513 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1514 inline typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::type
Chris@16 1515 get(edge_all_t, BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1516 {
Chris@16 1517 return g.m_forward.get_edge_bundle(get(edge_index, g));
Chris@16 1518 }
Chris@16 1519
Chris@16 1520 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1521 inline typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::const_type
Chris@16 1522 get(edge_all_t, const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1523 {
Chris@16 1524 return g.m_forward.get_edge_bundle(get(edge_index, g));
Chris@16 1525 }
Chris@16 1526
Chris@16 1527 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1528 inline EdgeProperty&
Chris@16 1529 get(edge_all_t,
Chris@16 1530 BOOST_CSR_GRAPH_TYPE& g,
Chris@16 1531 const typename BOOST_CSR_GRAPH_TYPE::edge_descriptor& e)
Chris@16 1532 {
Chris@16 1533 return get(edge_all, g)[e];
Chris@16 1534 }
Chris@16 1535
Chris@16 1536 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1537 inline const EdgeProperty&
Chris@16 1538 get(edge_all_t,
Chris@16 1539 const BOOST_CSR_GRAPH_TYPE& g,
Chris@16 1540 const typename BOOST_CSR_GRAPH_TYPE::edge_descriptor& e)
Chris@16 1541 {
Chris@16 1542 return get(edge_all, g)[e];
Chris@16 1543 }
Chris@16 1544
Chris@16 1545 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1546 inline void
Chris@16 1547 put(edge_all_t,
Chris@16 1548 BOOST_CSR_GRAPH_TYPE& g,
Chris@16 1549 const typename BOOST_CSR_GRAPH_TYPE::edge_descriptor& e,
Chris@16 1550 const EdgeProperty& val)
Chris@16 1551 {
Chris@16 1552 put(get(edge_all, g), e, val);
Chris@16 1553 }
Chris@16 1554
Chris@16 1555 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1556 inline typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::type
Chris@16 1557 get(graph_all_t, BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1558 {
Chris@16 1559 return typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::type(g.m_property);
Chris@16 1560 }
Chris@16 1561
Chris@16 1562 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1563 inline typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::const_type
Chris@16 1564 get(graph_all_t, const BOOST_CSR_GRAPH_TYPE& g)
Chris@16 1565 {
Chris@16 1566 return typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::const_type(g.m_property);
Chris@16 1567 }
Chris@16 1568
Chris@16 1569 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1570 inline GraphProperty&
Chris@16 1571 get(graph_all_t,
Chris@16 1572 BOOST_CSR_GRAPH_TYPE& g,
Chris@16 1573 BOOST_CSR_GRAPH_TYPE*)
Chris@16 1574 {
Chris@16 1575 return g.m_property;
Chris@16 1576 }
Chris@16 1577
Chris@16 1578 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1579 inline const GraphProperty&
Chris@16 1580 get(graph_all_t,
Chris@16 1581 const BOOST_CSR_GRAPH_TYPE& g,
Chris@16 1582 BOOST_CSR_GRAPH_TYPE*)
Chris@16 1583 {
Chris@16 1584 return g.m_property;
Chris@16 1585 }
Chris@16 1586
Chris@16 1587 template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
Chris@16 1588 inline void
Chris@16 1589 put(graph_all_t,
Chris@16 1590 BOOST_CSR_GRAPH_TYPE& g,
Chris@16 1591 BOOST_CSR_GRAPH_TYPE*,
Chris@16 1592 const GraphProperty& val)
Chris@16 1593 {
Chris@16 1594 g.m_property = val;
Chris@16 1595 }
Chris@16 1596
Chris@16 1597 #undef BOOST_CSR_GRAPH_TYPE
Chris@16 1598 #undef BOOST_CSR_GRAPH_TEMPLATE_PARMS
Chris@16 1599 #undef BOOST_DIR_CSR_GRAPH_TYPE
Chris@16 1600 #undef BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS
Chris@16 1601 #undef BOOST_BIDIR_CSR_GRAPH_TYPE
Chris@16 1602 #undef BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS
Chris@16 1603
Chris@16 1604 } // end namespace boost
Chris@16 1605
Chris@16 1606 #endif // BOOST_GRAPH_COMPRESSED_SPARSE_ROW_GRAPH_HPP