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/data_structures/internal/AssociationMapView.hpp"
10#include "CLUEstering/detail/concepts.hpp"
11#include "CLUEstering/internal/alpaka/config.hpp"
12#include "CLUEstering/internal/alpaka/memory.hpp"
13
14#include <alpaka/alpaka.hpp>
15
16namespace clue {
17
18 template <concepts::device TDev>
19 class AssociationMap;
20
21 namespace internal {
22 template <clue::concepts::queue TQueue>
23 auto make_associator(TQueue& queue, std::span<int32_t> associations, int32_t elements);
24 auto make_associator(std::span<int32_t> associations, int32_t elements)
25 -> AssociationMap<alpaka::DevCpu>;
26 } // namespace internal
27
32 template <concepts::device TDev = clue::Device>
34 public:
35 using key_type = int32_t;
36 using mapped_type = int32_t;
37 using value_type = std::pair<key_type, mapped_type>;
38 using size_type = std::size_t;
39 using iterator = mapped_type*;
40 using const_iterator = const mapped_type*;
41
42 struct Extents {
43 size_type keys;
44 size_type values;
45 };
46
48 AssociationMap() = default;
53 AssociationMap(size_type nelements, size_type nbins)
54 requires std::same_as<TDev, alpaka::DevCpu>;
60 AssociationMap(size_type nelements, size_type nbins, const TDev& dev);
61
67 template <concepts::queue TQueue>
68 AssociationMap(size_type nelements, size_type nbins, TQueue& queue);
69
73 auto size() const;
77 auto extents() const;
78
81 iterator begin();
84 const_iterator begin() const;
87 const_iterator cbegin() const;
88
91 iterator end();
94 const_iterator end() const;
97 const_iterator cend() const;
98
99 // TODO: the STL implementation for std::flat_multimap returns any element with the given key,
100 // Should we do the same? Should we return the first element or return a pair that gives the entire range?
101 // In the first case it would be equavalent to lower_bound, in the second case it would be equivalent to equal_range.
102 iterator find(key_type key);
103 const_iterator find(key_type key) const;
104
109 size_type count(key_type key) const;
110
115 bool contains(key_type key) const;
116
121 iterator lower_bound(key_type key);
126 const_iterator lower_bound(key_type key) const;
127
132 iterator upper_bound(key_type key);
137 const_iterator upper_bound(key_type key) const;
138
143 std::pair<iterator, iterator> equal_range(key_type key);
148 std::pair<const_iterator, const_iterator> equal_range(key_type key) const;
149
150 private:
151 device_buffer<TDev, mapped_type[]> m_indexes;
152 device_buffer<TDev, key_type[]> m_offsets;
153 AssociationMapView m_view;
154 size_type m_nbins;
155
156 ALPAKA_FN_HOST void initialize(size_type nelements, size_type nbins)
157 requires std::same_as<TDev, alpaka::DevCpu>;
158
159 template <concepts::queue TQueue>
160 ALPAKA_FN_HOST void initialize(size_type nelements, size_type nbins, TQueue& queue);
161
162 ALPAKA_FN_HOST void reset(size_type nelements, size_type nbins)
163 requires std::same_as<TDev, alpaka::DevCpu>;
164
165 template <concepts::queue TQueue>
166 ALPAKA_FN_HOST void reset(TQueue& queue, size_type nelements, size_type nbins);
167
168 template <concepts::accelerator TAcc, typename TFunc, concepts::queue TQueue>
169 ALPAKA_FN_HOST void fill(size_type size, TFunc func, TQueue& queue);
170
171 ALPAKA_FN_HOST void fill(size_type size, std::span<key_type> associations)
172 requires std::same_as<TDev, alpaka::DevCpu>;
173
174 template <concepts::accelerator TAcc, concepts::queue TQueue>
175 ALPAKA_FN_HOST void fill(size_type size, std::span<key_type> associations, TQueue& queue);
176
177 const AssociationMapView& view() const;
178 AssociationMapView& view();
179
180 ALPAKA_FN_HOST const auto& indexes() const;
181 ALPAKA_FN_HOST auto& indexes();
182
183 ALPAKA_FN_ACC Span<int32_t> indexes(size_type bin_id);
184 ALPAKA_FN_HOST device_view<TDev, int32_t[]> indexes(const TDev& dev, size_type bin_id);
185 ALPAKA_FN_ACC Span<int32_t> operator[](size_type bin_id);
186
187 ALPAKA_FN_HOST const device_buffer<TDev, int32_t[]>& offsets() const;
188 ALPAKA_FN_HOST device_buffer<TDev, int32_t[]>& offsets();
189
190 ALPAKA_FN_ACC int32_t offsets(size_type bin_id) const;
191
192 template <concepts::device _TDev>
193 friend class Followers;
194
195 template <uint8_t Ndim, concepts::device _TDev>
196 friend class TilesAlpaka;
197
198 template <concepts::queue _TQueue>
199 friend auto clue::internal::make_associator(_TQueue&, std::span<int32_t>, int32_t);
200 friend auto clue::internal::make_associator(std::span<int32_t>, int32_t)
202 };
203
204 using host_associator = AssociationMap<alpaka::DevCpu>;
205
206} // namespace clue
207
208#include "CLUEstering/data_structures/detail/AssociationMap.hpp"
The AssociationMap class is a data structure that maps keys to values. It associates integer keys wit...
Definition AssociationMap.hpp:33
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)
Construct an AssociationMap with a specific number of elements and bins.
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:42