diff --git a/libgalois/include/galois/graphs/LS_LC_CSR_Graph.h b/libgalois/include/galois/graphs/LS_LC_CSR_Graph.h index d2a31c1da..67a90dd1a 100644 --- a/libgalois/include/galois/graphs/LS_LC_CSR_Graph.h +++ b/libgalois/include/galois/graphs/LS_LC_CSR_Graph.h @@ -79,7 +79,7 @@ class LS_LC_CSR_Graph : private boost::noncopyable { static constexpr bool HasEdgeData = !std::is_same_v; using VertexDataStore = - std::conditional_t, + std::conditional_t, typename std::tuple<>>; using EdgeDataStore = std::conditional_t< HasEdgeData, @@ -123,7 +123,7 @@ class LS_LC_CSR_Graph : private boost::noncopyable { LS_LC_CSR_Graph(uint64_t num_vertices) : m_vertices(num_vertices, VertexMetadata()) { if constexpr (HasVertexData) { - m_vertex_data.allocateBlocked(num_vertices); + m_vertex_data.resize(num_vertices); } } @@ -158,6 +158,30 @@ class LS_LC_CSR_Graph : private boost::noncopyable { VertexRange vertices() { return VertexRange(begin(), end()); } + VertexTopologyID addVertexTopologyOnly() { + m_vertices.emplace_back(); + if constexpr (HasVertexData) { + m_vertex_data.resize(m_vertices.size()); + } + return m_vertices.size() - 1; + } + + // Adds multiple vertices to the graph. The new vertices will be assigned + // consecutive topology IDs, and the lowest new ID is returned. + template > + VertexTopologyID addVertices(std::vector data) { + VertexTopologyID const start = m_vertices.size(); + m_vertices.resize(m_vertices.size() + data.size()); + m_vertex_data.resize(m_vertices.size()); + + galois::do_all( + galois::iterate(0ul, data.size()), + [&](VertexTopologyID const& off) { setData(start + off, data[off]); }); + return start; + } + + size_t getDegree(VertexTopologyID id) { return m_vertices[id].degree; } + VertexTopologyID getEdgeDst(EdgeHandle eh) { return getEdgeMetadata(eh).dst; } template > diff --git a/libgalois/test/graph-compile-lscsr.cpp b/libgalois/test/graph-compile-lscsr.cpp index 3f6448b2c..b09298010 100644 --- a/libgalois/test/graph-compile-lscsr.cpp +++ b/libgalois/test/graph-compile-lscsr.cpp @@ -74,6 +74,15 @@ int main() { g.setData(3, 3); GALOIS_ASSERT(g.getData(3) == 3); + size_t four = g.addVertices({4, 5, 6, 7}); + + for (size_t ii = 0; ii < 4; ++ii) { + // make sure previous data survived the resize + GALOIS_ASSERT(g.getData(ii) == ii); + // check the new vertex data + GALOIS_ASSERT(g.getData(four + ii) == 4 + ii); + } + g.addEdges(0, {1, 2, 3}, {1, 2, 3}); for (auto const& handle : g.edges(0)) { GALOIS_ASSERT(g.getEdgeDst(handle) == g.getEdgeData(handle));