diff --git a/include/boost/graph/adj_list_serialize.hpp b/include/boost/graph/adj_list_serialize.hpp index 85f7e2ed4..381f0a455 100644 --- a/include/boost/graph/adj_list_serialize.hpp +++ b/include/boost/graph/adj_list_serialize.hpp @@ -9,6 +9,8 @@ #ifndef BOOST_GRAPH_ADJ_LIST_SERIALIZE_HPP #define BOOST_GRAPH_ADJ_LIST_SERIALIZE_HPP +#include + #include #include #include @@ -43,17 +45,17 @@ 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; - int V = num_vertices(graph); - int E = num_edges(graph); + const auto V = num_vertices(graph); + const auto 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::unordered_map< Vertex, Vertex > indices(V); + Vertex num = 0; BGL_FORALL_VERTICES_T(v, graph, Graph) { indices[v] = num++; @@ -81,33 +83,37 @@ 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 VertexSizeType = typename graph_traits< Graph >::vertices_size_type; - unsigned int V; + VertexSizeType V; ar >> BOOST_SERIALIZATION_NVP(V); - unsigned int E; + + VertexSizeType 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; + Vertex u; + Vertex v; ar >> BOOST_SERIALIZATION_NVP(u); ar >> BOOST_SERIALIZATION_NVP(v); + Edge e; bool inserted; - boost::tie(e, inserted) = add_edge(verts[u], verts[v], graph); + boost::tie(e, inserted)= add_edge(verts[u], verts[v], graph); ar >> serialization::make_nvp( "edge_property", get(edge_all_t(), graph, e)); }