Metall  v0.29
A persistent memory allocator for data-centric analytics
csr_using_vector.hpp
Go to the documentation of this file.
1 // Copyright 2019 Lawrence Livermore National Security, LLC and other Metall
2 // Project Developers. See the top-level COPYRIGHT file for details.
3 //
4 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
5 
6 #ifndef METALL_EXAMPLE_GRAPH_DATA_STRUCTURE_CSR_USING_VECTOR_HPP
7 #define METALL_EXAMPLE_GRAPH_DATA_STRUCTURE_CSR_USING_VECTOR_HPP
8 
9 #include <memory>
10 #include <boost/container/vector.hpp>
11 
12 namespace bc = boost::container;
13 
18 template <typename index_t = uint64_t, typename vid_t = uint64_t,
19  typename allocator_t = std::allocator<char>>
21  private:
22  // Here, we declare allocator and vector types we need.
23  // To store the indices array and edges array in persistent memory,
24  // we have to pass the allocator type (allocator_t) to the vectors.
25 
26  // Allocator and vector types for the indices array
27  using index_allocator_t = typename std::allocator_traits<
28  allocator_t>::template rebind_alloc<index_t>;
29  using index_vector_t = bc::vector<index_t, index_allocator_t>;
30 
31  // Allocator and vector types for the edges array
32  using edge_allocator_t =
33  typename std::allocator_traits<allocator_t>::template rebind_alloc<vid_t>;
34  using edge_vector_t = bc::vector<vid_t, edge_allocator_t>;
35 
36  public:
37  csr_using_vector(const std::size_t num_vertices, const std::size_t num_edges,
38  allocator_t allocator = allocator_t())
39  : m_num_vertices(num_vertices),
40  m_num_edges(num_edges),
41  m_indices(m_num_vertices + 1, allocator),
42  m_edges(m_num_edges, allocator) {}
43 
45  index_t *indices() { return m_indices.data(); }
46 
48  vid_t *edges() { return m_edges.data(); }
49 
50  private:
51  const std::size_t m_num_vertices;
52  const std::size_t m_num_edges;
53  index_vector_t m_indices;
54  edge_vector_t m_edges;
55 };
56 
57 #endif // METALL_EXAMPLE_GRAPH_DATA_STRUCTURE_CSR_USING_VECTOR_HPP
Simple CSR graph data structure that can take a custom C++ allocator and be stored in persistent memo...
Definition: csr_using_vector.hpp:20
csr_using_vector(const std::size_t num_vertices, const std::size_t num_edges, allocator_t allocator=allocator_t())
Definition: csr_using_vector.hpp:37
vid_t * edges()
Returns a raw pointer to the edges array.
Definition: csr_using_vector.hpp:48
index_t * indices()
Returns a raw pointer to the indices array.
Definition: csr_using_vector.hpp:45