Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions include/boost/graph/adj_list_serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ namespace serialization
const unsigned int /* file_version */
)
{
typedef adjacency_list< OEL, VL, D, VP, EP, GP, EL > Graph;
typedef typename graph_traits< Graph >::vertex_descriptor Vertex;
using Graph = adjacency_list< OEL, VL, D, VP, EP, GP, EL >;
using Vertex = typename graph_traits< Graph >::vertex_descriptor;
using SerializedInteger = unsigned int;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to cause a problem for users with, however unlikely, graphs where vertices_size_type is std::size_t and actually have billions or trillions or vertices?

Also, it would waste space for users that have billions of tiny graphs where they have customized vertices_size_type to be unsigned char, etc?


int V = num_vertices(graph);
int E = num_edges(graph);
const SerializedInteger V = num_vertices(graph);
const SerializedInteger E = num_edges(graph);
ar << BOOST_SERIALIZATION_NVP(V);
ar << BOOST_SERIALIZATION_NVP(E);

// assign indices to vertices
std::map< Vertex, int > indices;
int num = 0;
std::map< Vertex, SerializedInteger > indices;
SerializedInteger num = 0;
BGL_FORALL_VERTICES_T(v, graph, Graph)
{
indices[v] = num++;
Expand Down Expand Up @@ -81,33 +82,38 @@ namespace serialization
const unsigned int /* file_version */
)
{
typedef adjacency_list< OEL, VL, D, VP, EP, GP, EL > Graph;
typedef typename graph_traits< Graph >::vertex_descriptor Vertex;
typedef typename graph_traits< Graph >::edge_descriptor Edge;
using Graph = adjacency_list< OEL, VL, D, VP, EP, GP, EL >;
using Vertex = typename graph_traits< Graph >::vertex_descriptor;
using Edge = typename graph_traits< Graph >::edge_descriptor;
using SerializedInteger = unsigned int;

unsigned int V;
SerializedInteger V;
ar >> BOOST_SERIALIZATION_NVP(V);
unsigned int E;

SerializedInteger E;
ar >> BOOST_SERIALIZATION_NVP(E);

std::vector< Vertex > verts(V);
int i = 0;
size_t i = 0;
while (V-- > 0)
{
Vertex v = add_vertex(graph);
const auto v = add_vertex(graph);
verts[i++] = v;
ar >> serialization::make_nvp(
"vertex_property", get(vertex_all_t(), graph, v));
}
while (E-- > 0)
{
int u;
int v;
SerializedInteger u;
SerializedInteger v;
ar >> BOOST_SERIALIZATION_NVP(u);
ar >> BOOST_SERIALIZATION_NVP(v);
const auto uu = static_cast<Vertex>(u);
const auto vv = static_cast<Vertex>(v);

Edge e;
bool inserted;
boost::tie(e, inserted) = add_edge(verts[u], verts[v], graph);
boost::tie(e, inserted)= add_edge(verts[uu], verts[vv], graph);
ar >> serialization::make_nvp(
"edge_property", get(edge_all_t(), graph, e));
}
Expand Down