16#ifndef RANS_INTERNAL_CONTAINERS_HISTOGRAMVIEW_H_
17#define RANS_INTERNAL_CONTAINERS_HISTOGRAMVIEW_H_
24#include <fairlogger/Logger.h>
32template <
typename Hist_IT>
37 using value_type =
typename std::iterator_traits<Hist_IT>::value_type;
55 [[nodiscard]]
inline size_t size()
const {
return std::distance(mBegin, mEnd); };
57 [[nodiscard]]
inline bool empty()
const {
return mBegin == mEnd; };
75 os << fmt::format(
"HistogramView: size {}, offset {}", view.
size(), view.
getOffset());
83 assert(iter >= this->
begin());
84 assert(iter < this->
end());
90 assert(mBegin != mEnd);
99 static_assert(std::is_same_v<typename std::iterator_traits<Hist_IT>::iterator_category, std::random_access_iterator_tag>,
"This template is defined only for random access iterators");
102template <
typename Hist_IT>
108 auto isZero = [](
const value_type&
i) {
return i == value_type{}; };
109 auto nonZeroBegin = std::find_if_not(
buffer.begin(),
buffer.end(), isZero);
110 auto nonZeroEnd = nonZeroBegin ==
buffer.end() ?
buffer.end() : std::find_if_not(std::make_reverse_iterator(
buffer.end()), std::make_reverse_iterator(
buffer.begin()), isZero).base();
112 std::ptrdiff_t newOffset;
113 if (nonZeroBegin == nonZeroEnd) {
114 newOffset =
buffer.getOffset();
116 newOffset =
buffer.getMin() + std::distance(
buffer.begin(), nonZeroBegin);
119 return {nonZeroBegin, nonZeroEnd, newOffset};
122template <
typename HistA_IT,
typename HistB_IT>
125 return histB.getOffset() - histA.getOffset();
128template <
typename HistA_IT,
typename HistB_IT>
134template <
typename HistA_IT,
typename HistB_IT>
147 const std::ptrdiff_t leftOffset =
getLeftOffset(histA, histB);
156template <
typename HistA_IT,
typename HistB_IT>
163 const std::ptrdiff_t leftOffset =
getLeftOffset(histA, histB);
164 if (leftOffset <= 0) {
166 return {histA.
end(), histA.
end(), 0};
176template <
typename HistA_IT,
typename HistB_IT>
185 if (rightOffset > 0) {
187 return {histA.
end(), histA.
end(), 0};
194 return {newBegin, histA.
end(), *newBegin};
198template <
typename container_T>
201 return {std::begin(container), std::end(container),
offset};
204template <
typename container_T>
207 return {std::cbegin(container), std::cend(container),
offset};
210namespace histogramview_impl
213template <
class,
class =
void>
214struct has_getOffset : std::false_type {
218struct has_getOffset<T,
std::void_t<decltype(std::declval<T>().getOffset())>> : std::true_type {
222inline constexpr bool has_getOffset_v = has_getOffset<T>::value;
226template <
typename container_T, std::enable_if_t<histogramview_impl::has_getOffset_v<container_T>,
bool> = true>
229 return {std::cbegin(container), std::cend(container), container.
getOffset()};
232template <
typename container_T, std::enable_if_t<histogramview_impl::has_getOffset_v<container_T>,
bool> = true>
235 return {std::begin(container), std::end(container), container.
getOffset()};
common helper classes and functions
helper functionalities useful for packing operations
const value_type & operator[](difference_type idx) const
const value_type * const_pointer
const value_type & const_reference
HistogramView(HistogramView &&)=default
reverse_iterator rend() const
std::reverse_iterator< iterator > reverse_iterator
difference_type getMax() const
reverse_iterator rbegin() const
difference_type getMin() const noexcept
HistogramView(const HistogramView &)=default
const_pointer data() const
friend std::ostream & operator<<(std::ostream &os, const HistogramView &view)
HistogramView(iterator begin, iterator end, difference_type offset=0)
HistogramView & operator=(const HistogramView &)=default
typename std::iterator_traits< Hist_IT >::value_type value_type
HistogramView & operator=(HistogramView &&)=default
std::ptrdiff_t difference_type
difference_type getOffset() const noexcept
Freq_IT advanceIter(Freq_IT iter, std::ptrdiff_t distance)
std::ptrdiff_t getLeftOffset(const HistogramView< HistA_IT > &histA, const HistogramView< HistB_IT > &histB) noexcept
HistogramView< HistA_IT > getIntersection(const HistogramView< HistA_IT > &histA, const HistogramView< HistB_IT > &histB)
auto makeHistogramView(container_T &container, std::ptrdiff_t offset) noexcept -> HistogramView< decltype(std::begin(container))>
HistogramView< Hist_IT > trim(const HistogramView< Hist_IT > &buffer)
HistogramView< HistA_IT > getRightTail(const HistogramView< HistA_IT > &histA, const HistogramView< HistB_IT > &histB)
std::ptrdiff_t getRightOffset(const HistogramView< HistA_IT > &histA, const HistogramView< HistB_IT > &histB)
HistogramView< HistA_IT > getLeftTail(const HistogramView< HistA_IT > &histA, const HistogramView< HistB_IT > &histB)
Defining DataPointCompositeObject explicitly as copiable.