Project
Loading...
Searching...
No Matches
Container.h
Go to the documentation of this file.
1// Copyright 2019-2023 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef RANS_INTERNAL_CONTAINERS_CONTAINER_H_
17#define RANS_INTERNAL_CONTAINERS_CONTAINER_H_
18
19#include <cstdint>
20#include <string>
21#include <algorithm>
22
27
28namespace o2::rans::internal
29{
30
31template <class container_T, class derived_T>
33{
34 public:
35 using source_type = typename container_T::source_type;
36 using value_type = typename container_T::value_type;
37 using container_type = container_T;
38 using size_type = typename container_type::size_type;
39 using difference_type = typename container_type::difference_type;
40 using reference = typename std::add_lvalue_reference_t<value_type>;
41 using const_reference = typename std::add_lvalue_reference_t<std::add_const_t<value_type>>;
42 using pointer = typename std::add_pointer_t<value_type>;
43 using const_pointer = typename std::add_pointer_t<std::add_const_t<value_type>>;
44 using const_iterator = typename container_type::const_iterator;
45
46 // accessors
47 [[nodiscard]] inline const_reference operator[](source_type sourceSymbol) const { return static_cast<const derived_T&>(*this)[sourceSymbol]; };
48
49 [[nodiscard]] inline const_iterator cbegin() const noexcept { return this->mContainer.cbegin(); };
50
51 [[nodiscard]] inline const_iterator cend() const noexcept { return this->mContainer.cend(); };
52
53 [[nodiscard]] inline const_iterator begin() const noexcept { return this->mContainer.begin(); };
54
55 [[nodiscard]] inline const_iterator end() const noexcept { return this->mContainer.end(); };
56
57 [[nodiscard]] inline size_type size() const noexcept { return this->mContainer.size(); };
58
59 [[nodiscard]] inline bool empty() const noexcept { return mNSamples == 0; };
60
61 [[nodiscard]] inline size_type getNumSamples() const noexcept { return mNSamples; };
62
63 [[nodiscard]] inline source_type getOffset() const noexcept { return static_cast<const derived_T*>(this)->getOffset(); };
64
65 [[nodiscard]] inline container_type release() && noexcept { return std::move(this->mContainer); };
66
67 protected:
68 template <typename T>
69 inline T countSamples(T frequency)
70 {
71 mNSamples += frequency;
72 return frequency;
73 };
74
75 Container() = default;
77
80};
81
82template <typename source_T, typename value_T>
83class VectorContainer : public Container<ShiftableVector<source_T, value_T>, VectorContainer<source_T, value_T>>
84{
86 friend base_type;
87
88 public:
96 using pointer = typename base_type::pointer;
99
100 [[nodiscard]] inline const_pointer data() const noexcept { return this->mContainer.data(); };
101
102 [[nodiscard]] inline const_reference operator[](source_type sourceSymbol) const { return this->mContainer[sourceSymbol]; };
103
104 [[nodiscard]] inline source_type getOffset() const noexcept { return this->mContainer.getOffset(); };
105
106 protected:
107 VectorContainer() = default;
109};
110
111template <typename source_T, typename value_T>
112class SparseVectorContainer : public Container<SparseVector<source_T, value_T>, SparseVectorContainer<source_T, value_T>>
113{
115 friend base_type;
116
117 public:
125 using pointer = typename base_type::pointer;
128
129 [[nodiscard]] inline const_reference operator[](source_type sourceSymbol) const { return this->mContainer[sourceSymbol]; };
130
131 [[nodiscard]] inline const_reference at(source_type sourceSymbol) const { return this->mContainer.at(sourceSymbol); };
132
133 [[nodiscard]] inline source_type getOffset() const noexcept { return this->mContainer.getOffset(); };
134
135 protected:
137};
138
139template <typename source_T, typename value_T>
140class HashContainer : public Container<HashTable<source_T, value_T>, HashContainer<source_T, value_T>>
141{
143 friend base_type;
144
145 public:
153 using pointer = typename base_type::pointer;
156
157 [[nodiscard]] inline const_reference operator[](source_type sourceSymbol) const { return this->mContainer[sourceSymbol]; };
158
159 [[nodiscard]] inline source_type getOffset() const noexcept { return 0; };
160
161 [[nodiscard]] inline const_reference getNullElement() const { return this->mContainer.getNullElement(); };
162
163 protected:
164 HashContainer() = default;
166 {
167 this->mContainer = container_type(std::move(nullElement));
168 };
169};
170
171template <typename source_T, typename value_T>
172class SetContainer : public Container<OrderedSet<source_T, value_T>, SetContainer<source_T, value_T>>
173{
175 friend base_type;
176
177 public:
185 using pointer = typename base_type::pointer;
188
189 [[nodiscard]] inline const_reference operator[](source_type sourceSymbol) const { return this->mContainer[sourceSymbol]; };
190
191 [[nodiscard]] inline source_type getOffset() const noexcept
192 {
194 if (!this->mContainer.empty()) {
195 offset = this->mContainer.begin()->first;
196 }
197 return offset;
198 };
199
200 [[nodiscard]] inline const_reference getNullElement() const { return this->mContainer.getNullElement(); };
201
202 protected:
203 SetContainer() = default;
205 {
206 this->mContainer = container_type(std::move(nullElement));
207 };
209 {
210 this->mContainer = container_type(std::move(container), std::move(nullElement), state);
211 };
212};
213
214} // namespace o2::rans::internal
215
216#endif /* RANS_INTERNAL_CONTAINERS_CONTAINER_H_ */
benchmark::State & state
Wrapper around absl::flat_hash_map to be used as a container for building histograms and LUTs.
Vector Wrapper with contiguous but shifted, integer indexing. Base of all frequency container classes...
Vector Wrapper with contiguous but shifted, integer indexing. Base of all frequency container classes...
Vector Wrapper with contiguous but shifted, integer indexing. Base of all frequency container classes...
const_reference operator[](source_type sourceSymbol) const
Definition Container.h:47
typename std::add_lvalue_reference_t< std::add_const_t< value_type > > const_reference
Definition Container.h:41
typename std::add_pointer_t< std::add_const_t< value_type > > const_pointer
Definition Container.h:43
const_iterator cbegin() const noexcept
Definition Container.h:49
typename container_T::value_type value_type
Definition Container.h:36
typename std::add_pointer_t< value_type > pointer
Definition Container.h:42
size_type size() const noexcept
Definition Container.h:57
typename container_type::difference_type difference_type
Definition Container.h:39
T countSamples(T frequency)
Definition Container.h:69
const_iterator begin() const noexcept
Definition Container.h:53
typename std::add_lvalue_reference_t< value_type > reference
Definition Container.h:40
bool empty() const noexcept
Definition Container.h:59
typename container_type::const_iterator const_iterator
Definition Container.h:44
const_iterator cend() const noexcept
Definition Container.h:51
source_type getOffset() const noexcept
Definition Container.h:63
container_type release() &&noexcept
Definition Container.h:65
size_type getNumSamples() const noexcept
Definition Container.h:61
Container(size_type size, source_type offset)
Definition Container.h:76
typename container_T::source_type source_type
Definition Container.h:35
const_iterator end() const noexcept
Definition Container.h:55
typename container_type::size_type size_type
Definition Container.h:38
HashContainer(value_type nullElement)
Definition Container.h:165
const_reference operator[](source_type sourceSymbol) const
Definition Container.h:157
typename base_type::value_type value_type
Definition Container.h:147
const_reference getNullElement() const
Definition Container.h:161
typename base_type::size_type size_type
Definition Container.h:149
typename base_type::const_pointer const_pointer
Definition Container.h:154
typename base_type::const_reference const_reference
Definition Container.h:152
source_type getOffset() const noexcept
Definition Container.h:159
typename base_type::difference_type difference_type
Definition Container.h:150
typename base_type::reference reference
Definition Container.h:151
typename base_type::container_type container_type
Definition Container.h:148
typename base_type::pointer pointer
Definition Container.h:153
typename base_type::const_iterator const_iterator
Definition Container.h:155
typename base_type::source_type source_type
Definition Container.h:146
SetContainer(container_type container, value_type nullElement, OrderedSetState state=OrderedSetState::unordered)
Definition Container.h:208
typename base_type::difference_type difference_type
Definition Container.h:182
typename base_type::const_reference const_reference
Definition Container.h:184
typename base_type::reference reference
Definition Container.h:183
typename base_type::const_pointer const_pointer
Definition Container.h:186
typename base_type::container_type container_type
Definition Container.h:180
SetContainer(value_type nullElement)
Definition Container.h:204
const_reference operator[](source_type sourceSymbol) const
Definition Container.h:189
typename base_type::value_type value_type
Definition Container.h:179
source_type getOffset() const noexcept
Definition Container.h:191
typename base_type::const_iterator const_iterator
Definition Container.h:187
const_reference getNullElement() const
Definition Container.h:200
typename base_type::source_type source_type
Definition Container.h:178
typename base_type::pointer pointer
Definition Container.h:185
typename base_type::size_type size_type
Definition Container.h:181
const_reference operator[](source_type sourceSymbol) const
Definition Container.h:129
const_reference at(source_type sourceSymbol) const
Definition Container.h:131
source_type getOffset() const noexcept
Definition Container.h:133
typename base_type::pointer pointer
Definition Container.h:125
typename base_type::difference_type difference_type
Definition Container.h:122
typename base_type::source_type source_type
Definition Container.h:118
typename base_type::const_iterator const_iterator
Definition Container.h:127
typename base_type::value_type value_type
Definition Container.h:119
typename base_type::reference reference
Definition Container.h:123
typename base_type::container_type container_type
Definition Container.h:120
typename base_type::const_pointer const_pointer
Definition Container.h:126
typename base_type::const_reference const_reference
Definition Container.h:124
typename base_type::size_type size_type
Definition Container.h:121
VectorContainer(size_type size, source_type offset)
Definition Container.h:108
typename base_type::reference reference
Definition Container.h:94
typename base_type::size_type size_type
Definition Container.h:92
typename base_type::const_pointer const_pointer
Definition Container.h:97
typename base_type::const_reference const_reference
Definition Container.h:95
typename base_type::value_type value_type
Definition Container.h:90
typename base_type::pointer pointer
Definition Container.h:96
typename base_type::const_iterator const_iterator
Definition Container.h:98
typename base_type::container_type container_type
Definition Container.h:91
typename base_type::source_type source_type
Definition Container.h:89
const_reference operator[](source_type sourceSymbol) const
Definition Container.h:102
const_pointer data() const noexcept
Definition Container.h:100
typename base_type::difference_type difference_type
Definition Container.h:93
source_type getOffset() const noexcept
Definition Container.h:104
GLsizeiptr size
Definition glcorearb.h:659
GLintptr offset
Definition glcorearb.h:660