CLUEstering
High-performance density-based weighted clustering library developed at CERN
Loading...
Searching...
No Matches
AssociationMap.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "CLUEstering/core/detail/defines.hpp"
8#include "CLUEstering/data_structures/internal/Span.hpp"
9#include "CLUEstering/detail/concepts.hpp"
10#include "CLUEstering/internal/alpaka/config.hpp"
11#include "CLUEstering/internal/alpaka/memory.hpp"
12
13#include <alpaka/alpaka.hpp>
14
15namespace clue {
16
17 namespace test {
18 template <concepts::queue _TQueue>
19 auto build_map(_TQueue&, std::span<const int32_t>, int32_t);
20 }
21
22 namespace concepts = detail::concepts;
23
24 struct AssociationMapView;
25
30 template <concepts::device TDev = clue::Device>
32 public:
33 using key_type = int32_t;
34 using mapped_type = int32_t;
35 using value_type = std::pair<key_type, mapped_type>;
36 using size_type = std::size_t;
37 using iterator = mapped_type*;
38 using const_iterator = const mapped_type*;
39
40 struct Extents {
41 size_type keys;
42 size_type values;
43 };
44
46 AssociationMap() = default;
52 AssociationMap(size_type nelements, size_type nbins, const TDev& dev);
53
59 template <concepts::queue TQueue>
60 AssociationMap(size_type nelements, size_type nbins, TQueue& queue);
61
65 auto size() const;
69 auto extents() const;
70
73 iterator begin();
76 const_iterator begin() const;
79 const_iterator cbegin() const;
80
83 iterator end();
86 const_iterator end() const;
89 const_iterator cend() const;
90
91 // TODO: the STL implementation for std::flat_multimap returns any element with the given key,
92 // Should we do the same? Should we return the first element or return a pair that gives the entire range?
93 // In the first case it would be equavalent to lower_bound, in the second case it would be equivalent to equal_range.
94 iterator find(key_type key);
95 const_iterator find(key_type key) const;
96
101 size_type count(key_type key) const;
102
107 bool contains(key_type key) const;
108
113 iterator lower_bound(key_type key);
118 const_iterator lower_bound(key_type key) const;
119
124 iterator upper_bound(key_type key);
129 const_iterator upper_bound(key_type key) const;
130
135 std::pair<iterator, iterator> equal_range(key_type key);
140 std::pair<const_iterator, const_iterator> equal_range(key_type key) const;
141
142 private:
143 device_buffer<TDev, mapped_type[]> m_indexes;
144 device_buffer<TDev, key_type[]> m_offsets;
145 host_buffer<AssociationMapView> m_hview;
146 device_buffer<TDev, AssociationMapView> m_view;
147 size_type m_nbins;
148
149 template <concepts::queue TQueue>
150 ALPAKA_FN_HOST void initialize(size_type nelements, size_type nbins, TQueue& queue);
151
152 template <concepts::queue TQueue>
153 ALPAKA_FN_HOST void reset(TQueue& queue, size_type nelements, size_type nbins);
154
155 template <concepts::accelerator TAcc, typename TFunc, concepts::queue TQueue>
156 ALPAKA_FN_HOST void fill(size_type size, TFunc func, TQueue& queue);
157
158 template <concepts::accelerator TAcc, concepts::queue TQueue>
159 ALPAKA_FN_HOST void fill(size_type size, std::span<key_type> associations, TQueue& queue);
160
161 AssociationMapView* view();
162
163 ALPAKA_FN_HOST const auto& indexes() const;
164 ALPAKA_FN_HOST auto& indexes();
165
166 ALPAKA_FN_ACC Span<int32_t> indexes(size_type bin_id);
167 ALPAKA_FN_HOST device_view<TDev, int32_t[]> indexes(const TDev& dev, size_type bin_id);
168 ALPAKA_FN_ACC Span<int32_t> operator[](size_type bin_id);
169
170 ALPAKA_FN_HOST const device_buffer<TDev, int32_t[]>& offsets() const;
171 ALPAKA_FN_HOST device_buffer<TDev, int32_t[]>& offsets();
172
173 ALPAKA_FN_ACC int32_t offsets(size_type bin_id) const;
174
175 template <concepts::device _TDev>
176 friend class Followers;
177
178 template <uint8_t Ndim, concepts::device _TDev>
179 friend class TilesAlpaka;
180
181 template <concepts::queue _TQueue>
182 friend auto clue::test::build_map(_TQueue&, std::span<key_type>, int32_t);
183 };
184
185} // namespace clue
186
187#include "CLUEstering/data_structures/detail/AssociationMap.hpp"
AssociationMap(size_type nelements, size_type nbins, TQueue &queue)
Construct an AssociationMap with a specific number of elements and bins.
std::pair< const_iterator, const_iterator > equal_range(key_type key) const
Get the const range of elements with a given key.
AssociationMap()=default
Construct an empty AssociationMap.
const_iterator end() const
Return const iterator to the end of the content buffer.
std::pair< iterator, iterator > equal_range(key_type key)
Get the range of elements with a given key.
size_type count(key_type key) const
Count the number of elements with the given key.
const_iterator lower_bound(key_type key) const
Get the const iterator to the first element with a given key.
auto size() const
Return the number of bins in the map.
iterator end()
Return iterator to the end of the content buffer.
AssociationMap(size_type nelements, size_type nbins, const TDev &dev)
Construct an AssociationMap with a specific number of elements and bins.
auto extents() const
Return the extents of the internal buffers.
const_iterator cend() const
Return const iterator to the end of the content buffer.
const_iterator begin() const
Return const iterator to the beginning of the content buffer.
const_iterator upper_bound(key_type key) const
Get the const iterator to the first element with a key greater than the given key.
iterator lower_bound(key_type key)
Get the iterator to the first element with a given key.
iterator upper_bound(key_type key)
Get the iterator to the first element with a key greater than the given key.
iterator begin()
Return iterator to the beginning of the content buffer.
const_iterator cbegin() const
Return const iterator to the beginning of the content buffer.
bool contains(key_type key) const
Check if the map contains elements with a given key.
Definition AssociationMap.hpp:40