Project
Loading...
Searching...
No Matches
ReverseSymbolLookupTable.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_REVERSESYMBOLLOOKUPTABLE_H_
17#define RANS_INTERNAL_CONTAINERS_REVERSESYMBOLLOOKUPTABLE_H_
18
19#include <vector>
20#include <type_traits>
21#include <fairlogger/Logger.h>
22
25
26namespace o2::rans::internal
27{
28
29template <typename source_T>
31{
32 public:
35 using count_type = uint32_t;
36 using size_type = std::size_t;
37 using difference_type = std::ptrdiff_t;
38 using container_type = std::vector<source_type>;
39 using iterator_type = const source_type*;
40
41 // TODO(milettri): fix once ROOT cling respects the standard http://wg21.link/p1286r2
42 inline ReverseSymbolLookupTable() noexcept {}; // NOLINT
43
44 template <typename container_T>
46 {
47 if (renormedHistogram.empty()) {
48 LOG(warning) << "SymbolStatistics of empty message passed to " << __func__;
49 }
50
51 mLut.reserve(renormedHistogram.getNumSamples());
52 const auto [trimmedBegin, trimmedEnd] = internal::trim(renormedHistogram);
53
54 internal::forEachIndexValue(renormedHistogram, trimmedBegin, trimmedEnd, [&](const source_type& sourceSymbol, const count_type& frequency) {
55 if (frequency > 0) {
56 this->mLut.insert(mLut.end(), frequency, sourceSymbol);
57 }
58 });
59 };
60
61 inline size_type size() const noexcept { return mLut.size(); };
62
63 inline bool isIncompressible(count_type cumul) const noexcept
64 {
65 return cumul >= this->size();
66 };
67
68 inline source_type operator[](count_type cumul) const noexcept
69 {
70 assert(cumul < this->size());
71 return mLut[cumul];
72 };
73
74 inline iterator_type begin() const noexcept { return mLut.data(); };
75 inline iterator_type end() const noexcept { return mLut.data() + size(); };
76
78};
79
80} // namespace o2::rans::internal
81
82#endif /* RANS_INTERNAL_CONTAINERS_REVERSESYMBOLLOOKUPTABLE_H_ */
Histogram renormed to sum of frequencies being 2^P for use in fast rans coding.
common helper classes and functions
bool isIncompressible(count_type cumul) const noexcept
ReverseSymbolLookupTable(const RenormedHistogramConcept< container_T > &renormedHistogram)
source_type operator[](count_type cumul) const noexcept
auto trim(typename container_T::iterator begin, typename container_T::iterator end, typename container_T::const_reference zeroElem={}) -> std::pair< typename container_T::iterator, typename container_T::iterator >
Definition algorithm.h:104
void forEachIndexValue(const container_T &container, typename container_T::const_iterator begin, typename container_T::const_iterator end, F functor)
Definition algorithm.h:80
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"