Metall v0.30
A persistent memory allocator for data-centric analytics
 
Loading...
Searching...
No Matches
adjacency_list.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_ADJACENCY_LIST_HPP
7#define METALL_EXAMPLE_GRAPH_DATA_STRUCTURE_ADJACENCY_LIST_HPP
8
9#include <memory>
10#include <boost/container/scoped_allocator.hpp>
11#include <boost/container/vector.hpp>
12#include <boost/unordered_map.hpp>
13
14using boost::unordered_map;
15using boost::container::scoped_allocator_adaptor;
16using boost::container::vector;
17
21template <typename vid_t = uint64_t,
22 typename allocator_t = std::allocator<char>>
24 private:
25 // Inner vector type
26 using index_allocator_t =
27 typename std::allocator_traits<allocator_t>::template rebind_alloc<vid_t>;
28 using vector_type = vector<vid_t, index_allocator_t>;
29
30 // To use custom allocator in multi-level containers, you have to use
31 // scoped_allocator_adaptor in the most outer container so that the inner
32 // containers obtain their allocator arguments from the outer containers's
33 // scoped_allocator_adaptor See:
34 // https://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor
35 using map_allocator_type = scoped_allocator_adaptor<
36 typename std::allocator_traits<allocator_t>::template rebind_alloc<
37 std::pair<const vid_t, vector_type>>>;
38 using map_type = unordered_map<vid_t, vector_type, std::hash<vid_t>,
39 std::equal_to<vid_t>, map_allocator_type>;
40
41 public:
42 explicit adjacency_list(allocator_t allocator = allocator_t())
43 : m_map(allocator) {}
44
45 void add_edge(vid_t source, vid_t target) {
46 m_map[source].emplace_back(target);
47 }
48
49 auto edges_begin(const vid_t source) { return m_map[source].begin(); }
50
51 auto edges_end(const vid_t source) { return m_map[source].end(); }
52
53 private:
54 map_type m_map;
55};
56
57#endif // METALL_EXAMPLE_GRAPH_DATA_STRUCTURE_ADJACENCY_LIST_HPP
Simple adjacency-list graph data structure that can take a custom C++ allocator and be stored in pers...
Definition adjacency_list.hpp:23
auto edges_begin(const vid_t source)
Definition adjacency_list.hpp:49
adjacency_list(allocator_t allocator=allocator_t())
Definition adjacency_list.hpp:42
auto edges_end(const vid_t source)
Definition adjacency_list.hpp:51
void add_edge(vid_t source, vid_t target)
Definition adjacency_list.hpp:45