Project
Loading...
Searching...
No Matches
RenormedHistogram.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_RENORMEDHISTOGRAM_H_
17#define RANS_INTERNAL_CONTAINERS_RENORMEDHISTOGRAM_H_
18
19#include <numeric>
20#include <fairlogger/Logger.h>
21
24
25namespace o2::rans
26{
27
28template <class container_T>
29class RenormedHistogramConcept : public container_T
30{
31 using base_type = container_T;
32
33 public:
34 using source_type = typename base_type::source_type;
35 using value_type = typename base_type::value_type;
36 using container_type = typename base_type::container_type;
37 using size_type = typename base_type::size_type;
38 using difference_type = typename base_type::difference_type;
39 using reference = typename base_type::reference;
40 using const_reference = typename base_type::const_reference;
41 using pointer = typename base_type::pointer;
42 using const_pointer = typename base_type::const_pointer;
43 using const_iterator = typename base_type::const_iterator;
44
45 RenormedHistogramConcept() : base_type(){};
46
47 inline RenormedHistogramConcept(container_type frequencies, size_t renormingBits, value_type nIncompressible) : mNIncompressible(nIncompressible)
48 {
49 this->mContainer = std::move(frequencies);
50 this->mNSamples = utils::pow2(renormingBits);
51
52#if !defined(NDEBUG)
53 size_t nSamples = std::accumulate(this->begin(), this->end(), 0, [](const auto& a, const auto& b) {
54 if constexpr (std::is_integral_v<std::remove_reference_t<decltype(b)>>) {
55 return a + b;
56 } else {
57 return a + b.second;
58 }
59 });
60 nSamples += this->mNIncompressible;
61 assert(internal::isPow2(nSamples));
62 assert(nSamples == this->mNSamples);
63#endif
64 };
65
66 [[nodiscard]] inline size_t getRenormingBits() const noexcept { return utils::log2UInt(this->mNSamples); };
67
68 [[nodiscard]] inline bool isRenormedTo(size_t nBits) const noexcept { return nBits == this->getRenormingBits(); };
69
70 [[nodiscard]] inline value_type getIncompressibleSymbolFrequency() const noexcept { return mNIncompressible; };
71
72 [[nodiscard]] inline bool hasIncompressibleSymbol() const noexcept { return mNIncompressible != 0; };
73
74 private:
75 value_type mNIncompressible{};
76};
77
78template <typename source_T>
79using RenormedDenseHistogram = RenormedHistogramConcept<internal::VectorContainer<source_T, uint32_t>>;
80
81template <typename source_T>
82using RenormedAdaptiveHistogram = RenormedHistogramConcept<internal::SparseVectorContainer<source_T, uint32_t>>;
83
84template <typename source_T>
85using RenormedSparseHistogram = RenormedHistogramConcept<internal::SetContainer<source_T, uint32_t>>;
86
87template <typename container_T>
89{
90 return std::count_if(histogram.begin(), histogram.end(),
92 return v != typename RenormedHistogramConcept<container_T>::value_type{};
93 });
94}
95
96} // namespace o2::rans
97
98#endif /* RANS_INTERNAL_CONTAINERS_RENORMEDHISTOGRAM_H_ */
Abstract container class that defines and implements basic properties shared by histograms and lookup...
Non-owning, lightweight structure for histogram manipulation.
RenormedHistogramConcept(container_type frequencies, size_t renormingBits, value_type nIncompressible)
typename base_type::value_type value_type
bool isRenormedTo(size_t nBits) const noexcept
typename base_type::reference reference
typename base_type::size_type size_type
typename base_type::const_iterator const_iterator
value_type getIncompressibleSymbolFrequency() const noexcept
typename base_type::pointer pointer
size_t getRenormingBits() const noexcept
typename base_type::container_type container_type
typename base_type::const_pointer const_pointer
typename base_type::source_type source_type
typename base_type::difference_type difference_type
bool hasIncompressibleSymbol() const noexcept
typename base_type::const_reference const_reference
GLuint GLuint end
Definition glcorearb.h:469
const GLdouble * v
Definition glcorearb.h:832
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
constexpr bool isPow2(T x) noexcept
Definition utils.h:104
constexpr size_t pow2(size_t n) noexcept
Definition utils.h:165
constexpr T log2UInt(T x) noexcept
Definition utils.h:179
RenormedHistogramConcept< internal::SparseVectorContainer< source_T, uint32_t > > RenormedAdaptiveHistogram
RenormedHistogramConcept< internal::VectorContainer< source_T, uint32_t > > RenormedDenseHistogram
size_t countNUsedAlphabetSymbols(const AdaptiveHistogram< source_T > &histogram)
RenormedHistogramConcept< internal::SetContainer< source_T, uint32_t > > RenormedSparseHistogram