2
0
mirror of https://github.com/boostorg/graph.git synced 2026-02-27 05:02:22 +00:00

Removed old CSR interface; fixes #3135

[SVN r57898]
This commit is contained in:
Jeremiah Willcock
2009-11-24 18:38:28 +00:00
parent 5478788f98
commit b2636ec3ea
4 changed files with 26 additions and 400 deletions

View File

@@ -47,26 +47,6 @@
# error You will need a compiler that conforms better to the C++ standard.
#endif
#ifndef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
#if BOOST_VERSION >= 103800
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__)
#pragma message ("Using deprecated BGL compressed sparse row graph interface --")
#pragma message ("please see the documentation for the new interface and then")
#pragma message ("#define BOOST_GRAPH_USE_NEW_CSR_INTERFACE before including")
#pragma message ("<boost/graph/compressed_sparse_row_graph.hpp>")
#elif defined(__GNUC__) || defined(__HP_aCC) || defined(__SUNPRO_CC) || defined(__IBMCPP__)
#endif
#warning "Using deprecated BGL compressed sparse row graph interface --"
#warning "please see the documentation for the new interface and then"
#warning "#define BOOST_GRAPH_USE_NEW_CSR_INTERFACE before including"
#warning "<boost/graph/compressed_sparse_row_graph.hpp>"
#endif
#endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE
#ifndef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
#define BOOST_GRAPH_USE_OLD_CSR_INTERFACE
#endif
namespace boost {
// A tag type indicating that the graph in question is a compressed
@@ -78,7 +58,6 @@ struct csr_graph_tag;
// vertex.
enum edges_are_sorted_t {edges_are_sorted};
#ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
// A type (edges_are_sorted_global_t) and a value (edges_are_sorted_global)
// used to indicate that the edge list passed into the CSR graph is already
// sorted by source vertex.
@@ -131,8 +110,6 @@ enum construct_inplace_from_sources_and_targets_global_t {construct_inplace_from
// distributed CSR constructors.
enum edges_are_unsorted_global_t {edges_are_unsorted_global};
#endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE
/****************************************************************************
* Local helper macros to reduce typing and clutter later on. *
****************************************************************************/
@@ -155,7 +132,6 @@ enum edges_are_unsorted_global_t {edges_are_unsorted_global};
compressed_sparse_row_graph<bidirectionalS, VertexProperty, EdgeProperty, \
GraphProperty, Vertex, EdgeIndex>
#ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
namespace detail {
template <typename T>
struct default_construct_iterator: public boost::iterator_facade<default_construct_iterator<T>, T, boost::random_access_traversal_tag, const T&> {
@@ -188,7 +164,6 @@ namespace detail {
}
};
}
#endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE
/** Compressed sparse row graph.
*
@@ -280,7 +255,6 @@ class compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, Graph
compressed_sparse_row_graph(vertices_size_type numverts)
: inherited_vertex_properties(numverts), m_forward(numverts) {}
#ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
// From number of vertices and unsorted list of edges
template <typename MultiPassInputIterator>
compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
@@ -336,38 +310,6 @@ class compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, Graph
{
m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, ep_iter, numlocalverts, global_to_local, source_pred);
}
#endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE
#ifdef BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// From number of vertices and sorted list of edges (deprecated
// interface)
template<typename InputIterator>
compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
vertices_size_type numverts,
edges_size_type numedges = 0,
const GraphProperty& prop = GraphProperty())
: m_property(prop)
{
m_forward.assign_from_sorted_edges(edge_begin, edge_end, identity_property_map(), keep_all(), numverts, numedges);
inherited_vertex_properties::resize(numverts);
}
// From number of vertices and sorted list of edges (deprecated
// interface)
template<typename InputIterator, typename EdgePropertyIterator>
compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
EdgePropertyIterator ep_iter,
vertices_size_type numverts,
edges_size_type numedges = 0,
const GraphProperty& prop = GraphProperty())
: m_property(prop)
{
m_forward.assign_from_sorted_edges(edge_begin, edge_end, ep_iter, identity_property_map(), keep_all(), numverts, numedges);
inherited_vertex_properties::resize(numverts);
}
#endif // BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// From number of vertices and sorted list of edges (new interface)
template<typename InputIterator>
@@ -396,7 +338,6 @@ class compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, Graph
inherited_vertex_properties::resize(numverts);
}
#ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
// From number of vertices and sorted list of edges, filtered and global (new interface)
template<typename InputIterator, typename GlobalToLocal, typename SourcePred>
compressed_sparse_row_graph(edges_are_sorted_global_t,
@@ -565,8 +506,6 @@ class compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, Graph
m_forward.assign_sources_and_targets_global(sources, targets, edge_props, numlocalverts, global_to_local);
}
#endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE
// Requires IncidenceGraph and a vertex index map
template<typename Graph, typename VertexIndexMap>
@@ -644,7 +583,6 @@ class compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, Graph
inherited_vertex_properties::resize(numverts);
}
#ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
// Add edges from a sorted (smallest sources first) range of pairs and edge
// properties
template <typename BidirectionalIteratorOrig, typename EPIterOrig,
@@ -763,7 +701,6 @@ class compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, Graph
EPIterator ep_iter, EPIterator ep_iter_end) {
this->add_edges_internal(first, last, ep_iter, ep_iter_end, identity_property_map());
}
#endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE
using inherited_vertex_properties::operator[];
@@ -784,8 +721,6 @@ class compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, Graph
GraphProperty m_property;
};
#ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
// Bidir is only supported in this mode
template<typename VertexProperty,
typename EdgeProperty,
typename GraphProperty,
@@ -1153,7 +1088,6 @@ class compressed_sparse_row_graph<bidirectionalS, VertexProperty, EdgeProperty,
backward_type m_backward;
GraphProperty m_property;
};
#endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE
// Construction functions
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
@@ -1194,44 +1128,6 @@ add_vertices(typename BOOST_DIR_CSR_GRAPH_TYPE::vertices_size_type count, BOOST_
return old_num_verts_plus_one - 1;
}
#ifdef BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// This function requires that (src, tgt) be lexicographically at least as
// large as the largest edge in the graph so far
template<BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS>
inline typename BOOST_DIR_CSR_GRAPH_TYPE::edge_descriptor
add_edge(Vertex src, Vertex tgt, BOOST_DIR_CSR_GRAPH_TYPE& g) {
assert ((g.m_last_source == 0 || src >= g.m_last_source - 1) &&
src < num_vertices(g));
EdgeIndex num_edges_orig = g.m_forward.m_column.size();
for (; g.m_last_source <= src; ++g.m_last_source)
g.m_forward.m_rowstart[g.m_last_source] = num_edges_orig;
g.m_forward.m_rowstart[src + 1] = num_edges_orig + 1;
g.m_forward.m_column.push_back(tgt);
typedef typename BOOST_DIR_CSR_GRAPH_TYPE::edge_push_back_type push_back_type;
g.edge_properties().push_back(push_back_type());
return typename BOOST_DIR_CSR_GRAPH_TYPE::edge_descriptor(src, num_edges_orig);
}
// This function requires that src be at least as large as the largest source
// in the graph so far
template<BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS>
inline typename BOOST_DIR_CSR_GRAPH_TYPE::edge_descriptor
add_edge(Vertex src, Vertex tgt,
typename BOOST_DIR_CSR_GRAPH_TYPE::edge_bundled const& p,
BOOST_DIR_CSR_GRAPH_TYPE& g) {
assert ((g.m_last_source == 0 || src >= g.m_last_source - 1) &&
src < num_vertices(g));
EdgeIndex num_edges_orig = g.m_forward.m_column.size();
for (; g.m_last_source <= src; ++g.m_last_source)
g.m_forward.m_rowstart[g.m_last_source] = num_edges_orig;
g.m_forward.m_rowstart[src + 1] = num_edges_orig + 1;
g.m_forward.m_column.push_back(tgt);
g.edge_properties().push_back(p);
return typename BOOST_DIR_CSR_GRAPH_TYPE::edge_descriptor(src, num_edges_orig);
}
#endif // BOOST_GRAPH_USE_OLD_CSR_INTERFACE
#ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
// Add edges from a sorted (smallest sources first) range of pairs and edge
// properties
template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename BidirectionalIteratorOrig,
@@ -1316,7 +1212,6 @@ add_edge(Vertex src, Vertex tgt,
BOOST_DIR_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
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
@@ -1349,29 +1244,6 @@ target(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e,
return g.m_forward.m_column[e.idx];
}
#ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
namespace detail {
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
inline EdgeIndex get_actual_row_start
(const BOOST_CSR_GRAPH_TYPE& /*g*/,
EdgeIndex /*rowstart_i_minus_1*/, EdgeIndex rowstart_i)
{
return rowstart_i;
}
}
#else
namespace detail {
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
inline EdgeIndex get_actual_row_start
(const BOOST_CSR_GRAPH_TYPE& /*g*/,
EdgeIndex rowstart_i_minus_1, EdgeIndex rowstart_i)
{
// Special case to allow incremental construction
return (std::max)(rowstart_i_minus_1, rowstart_i);
}
}
#endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
inline std::pair<typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator,
typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator>
@@ -1382,8 +1254,7 @@ out_edges(Vertex v, const BOOST_CSR_GRAPH_TYPE& g)
EdgeIndex v_row_start = g.m_forward.m_rowstart[v];
EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1];
return std::make_pair(it(ed(v, v_row_start)),
it(ed(v, detail::get_actual_row_start
(g, v_row_start, next_row_start))));
it(ed(v, next_row_start)));
}
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
@@ -1392,11 +1263,9 @@ out_degree(Vertex v, const BOOST_CSR_GRAPH_TYPE& g)
{
EdgeIndex v_row_start = g.m_forward.m_rowstart[v];
EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1];
return detail::get_actual_row_start(g, v_row_start, next_row_start) - v_row_start;
return next_row_start - v_row_start;
}
#ifdef BOOST_GRAPH_USE_NEW_CSR_INTERFACE
template<BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS>
inline std::pair<typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator,
typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator>
@@ -1419,8 +1288,6 @@ in_degree(Vertex v, const BOOST_BIDIR_CSR_GRAPH_TYPE& g)
return next_row_start - v_row_start;
}
#endif // BOOST_GRAPH_USE_NEW_CSR_INTERFACE
// From AdjacencyGraph
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
inline std::pair<typename BOOST_CSR_GRAPH_TYPE::adjacency_iterator,
@@ -1430,9 +1297,7 @@ adjacent_vertices(Vertex v, const BOOST_CSR_GRAPH_TYPE& g)
EdgeIndex v_row_start = g.m_forward.m_rowstart[v];
EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1];
return std::make_pair(g.m_forward.m_column.begin() + v_row_start,
g.m_forward.m_column.begin() +
detail::get_actual_row_start
(g, v_row_start, next_row_start));
g.m_forward.m_column.begin() + next_row_start);
}
// Extra, common functions
@@ -1444,43 +1309,6 @@ vertex(typename graph_traits<BOOST_CSR_GRAPH_TYPE>::vertex_descriptor i,
return i;
}
#ifdef BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// These require that the out edges from a vertex are sorted, which is only
// guaranteed by the old interface
// Unlike for an adjacency_matrix, edge_range and edge take lg(out_degree(i))
// time
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
inline std::pair<typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator,
typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator>
edge_range(Vertex i, Vertex j, const BOOST_CSR_GRAPH_TYPE& g)
{
typedef typename std::vector<Vertex>::const_iterator adj_iter;
typedef typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator out_edge_iter;
typedef typename BOOST_CSR_GRAPH_TYPE::edge_descriptor edge_desc;
std::pair<adj_iter, adj_iter> raw_adjacencies = adjacent_vertices(i, g);
std::pair<adj_iter, adj_iter> adjacencies =
std::equal_range(raw_adjacencies.first, raw_adjacencies.second, j);
EdgeIndex idx_begin = adjacencies.first - g.m_forward.m_column.begin();
EdgeIndex idx_end = adjacencies.second - g.m_forward.m_column.begin();
return std::make_pair(out_edge_iter(edge_desc(i, idx_begin)),
out_edge_iter(edge_desc(i, idx_end)));
}
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
inline std::pair<typename BOOST_CSR_GRAPH_TYPE::edge_descriptor, bool>
edge(Vertex i, Vertex j, const BOOST_CSR_GRAPH_TYPE& g)
{
typedef typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator out_edge_iter;
std::pair<out_edge_iter, out_edge_iter> range = edge_range(i, j, g);
if (range.first == range.second)
return std::make_pair(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor(),
false);
else
return std::make_pair(*range.first, true);
}
#else // !BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// edge() can be provided in linear time for the new interface
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
@@ -1497,8 +1325,6 @@ edge(Vertex i, Vertex j, const BOOST_CSR_GRAPH_TYPE& g)
false);
}
#endif // !BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// Find an edge given its index in the graph
template<BOOST_CSR_GRAPH_TEMPLATE_PARMS>
inline typename BOOST_CSR_GRAPH_TYPE::edge_descriptor
@@ -1508,14 +1334,7 @@ edge_from_index(EdgeIndex idx, const BOOST_CSR_GRAPH_TYPE& g)
assert (idx < num_edges(g));
row_start_iter src_plus_1 =
std::upper_bound(g.m_forward.m_rowstart.begin(),
#ifdef BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// This handles the case where there are some vertices
// with rowstart 0 after the last provided vertex; this
// case does not happen with the new interface
g.m_forward.m_rowstart.begin() + g.m_last_source + 1,
#else // !BOOST_GRAPH_USE_OLD_CSR_INTERFACE
g.m_forward.m_rowstart.end(),
#endif // BOOST_GRAPH_USE_OLD_CSR_INTERFACE
idx);
// Get last source whose rowstart is at most idx
// upper_bound returns this position plus 1

View File

@@ -81,17 +81,9 @@ namespace detail {
std::vector<EdgeIndex> m_rowstart;
std::vector<Vertex> m_column;
#ifdef BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// This member is only needed to support add_edge(), which is not provided by
// the new interface
Vertex m_last_source; // Last source of added edge, plus one
#endif // BOOST_GRAPH_USE_OLD_CSR_INTERFACE
compressed_sparse_row_structure(Vertex numverts = 0)
: m_rowstart(numverts + 1, EdgeIndex(0)), m_column()
#ifdef BOOST_GRAPH_USE_OLD_CSR_INTERFACE
, m_last_source(numverts)
#endif
{}
// Rebuild graph from number of vertices and multi-pass unsorted list of
@@ -310,24 +302,12 @@ namespace detail {
for (Vertex i = 0; i != numverts; ++i) {
m_rowstart[i] = current_edge;
g_vertex v = ordered_verts_of_g[i];
#ifdef BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// Out edges in a single vertex are only sorted for the old interface
EdgeIndex num_edges_before_this_vertex = current_edge;
#endif // BOOST_GRAPH_USE_OLD_CSR_INTERFACE
g_out_edge_iter ei, ei_end;
for (tie(ei, ei_end) = out_edges(v, g); ei != ei_end; ++ei) {
m_column[current_edge++] = get(vi, target(*ei, g));
}
#ifdef BOOST_GRAPH_USE_OLD_CSR_INTERFACE
// Out edges in a single vertex are only sorted for the old interface
std::sort(m_column.begin() + num_edges_before_this_vertex,
m_column.begin() + current_edge);
#endif // BOOST_GRAPH_USE_OLD_CSR_INTERFACE
}
m_rowstart[numverts] = current_edge;
#ifdef BOOST_GRAPH_USE_OLD_CSR_INTERFACE
m_last_source = numverts;
#endif // BOOST_GRAPH_USE_OLD_CSR_INTERFACE
}
// Add edges from a sorted (smallest sources first) range of pairs and edge