31#ifndef ETL_HISTOGRAM_INCLUDED
32#define ETL_HISTOGRAM_INCLUDED
40#include "static_assert.h"
45 namespace private_histogram
50 template <
typename TCount,
size_t Max_Size_>
55 ETL_STATIC_ASSERT(etl::is_integral<TCount>::value,
"Only integral count allowed");
57 static ETL_CONSTANT
size_t Max_Size = Max_Size_;
59 typedef typename etl::array<TCount, Max_Size>::const_iterator const_iterator;
66 return accumulator.begin();
74 return accumulator.cbegin();
80 const_iterator
end()
const
82 return accumulator.end();
88 const_iterator
cend()
const
90 return accumulator.cend();
98 accumulator.fill(TCount(0));
104 ETL_CONSTEXPR
size_t size()
const
122 return etl::accumulate(accumulator.begin(), accumulator.end(),
size_t(0));
130 template <
typename TCount,
size_t Max_Size_>
131 ETL_CONSTANT
size_t histogram_common<TCount, Max_Size_>::Max_Size;
137 template <typename TKey, typename TCount, size_t Max_Size, int32_t Start_Index = etl::integral_limits<int32_t>::max>
144 ETL_STATIC_ASSERT(etl::is_integral<TKey>::value,
"Only integral keys allowed");
145 ETL_STATIC_ASSERT(etl::is_integral<TCount>::value,
"Only integral count allowed");
147 typedef TKey key_type;
148 typedef TCount count_type;
149 typedef TCount value_type;
156 this->accumulator.fill(count_type(0));
162 template <
typename TIterator>
165 this->accumulator.fill(count_type(0));
174 this->accumulator = other.accumulator;
183 this->accumulator = etl::move(other.accumulator);
192 this->accumulator = rhs.accumulator;
203 this->accumulator = etl::move(rhs.accumulator);
214 ++this->accumulator[
static_cast<size_t>(key - Start_Index)];
220 template <
typename TIterator>
221 void add(TIterator first, TIterator last)
223 while (first != last)
241 template <
typename TIterator>
252 return this->accumulator[
static_cast<size_t>(key - Start_Index)];
259 template <
typename TKey,
typename TCount,
size_t Max_Size>
266 ETL_STATIC_ASSERT(etl::is_integral<TKey>::value,
"Only integral keys allowed");
267 ETL_STATIC_ASSERT(etl::is_integral<TCount>::value,
"Only integral count allowed");
269 typedef TKey key_type;
270 typedef TCount count_type;
271 typedef TCount value_type;
277 : start_index(start_index_)
279 this->accumulator.fill(count_type(0));
285 template <
typename TIterator>
286 histogram(key_type start_index_, TIterator first, TIterator last)
287 : start_index(start_index_)
289 this->accumulator.fill(count_type(0));
298 this->accumulator = other.accumulator;
307 this->accumulator = etl::move(other.accumulator);
316 this->accumulator = rhs.accumulator;
327 this->accumulator = etl::move(rhs.accumulator);
338 ++this->accumulator[
static_cast<size_t>(key - start_index)];
344 template <
typename TIterator>
345 void add(TIterator first, TIterator last)
347 while (first != last)
365 template <
typename TIterator>
376 return this->accumulator[
static_cast<size_t>(key - start_index)];
381 key_type start_index;
387 template <
typename TKey,
typename TCount,
size_t Max_Size_>
396 ETL_STATIC_ASSERT(etl::is_integral<TCount>::value,
"Only integral count allowed");
398 static ETL_CONSTANT
size_t Max_Size = Max_Size_;
400 typedef TKey key_type;
401 typedef TCount count_type;
402 typedef typename accumulator_type::value_type value_type;
415 template <
typename TIterator>
426 this->accumulator = other.accumulator;
435 accumulator = etl::move(other.accumulator);
444 accumulator = rhs.accumulator;
455 accumulator = etl::move(rhs.accumulator);
466 return accumulator.begin();
474 return accumulator.cbegin();
480 const_iterator
end()
const
482 return accumulator.begin();
490 return accumulator.cbegin();
496 void add(
const key_type& key)
504 template <
typename TIterator>
505 void add(TIterator first, TIterator last)
507 while (first != last)
525 template <
typename TIterator>
536 static const value_type unused(key_type(), count_type(0));
540 if (itr != accumulator.end())
563 return accumulator.size();
579 count_type sum = count_type(0);
581 const_iterator itr = accumulator.begin();
583 while (itr != accumulator.end())
585 sum += (*itr).second;
589 return static_cast<size_t>(sum);
597 template <
typename TKey,
typename TCount,
size_t Max_Size_>
598 ETL_CONSTANT
size_t sparse_histogram<TKey, TCount, Max_Size_>::Max_Size;
histogram & operator=(const histogram &rhs)
Copy assignment.
Definition histogram.h:314
histogram(key_type start_index_, TIterator first, TIterator last)
Constructor.
Definition histogram.h:286
void add(key_type key)
Add.
Definition histogram.h:336
histogram(key_type start_index_)
Constructor.
Definition histogram.h:276
value_type operator[](key_type key) const
operator []
Definition histogram.h:374
void add(TIterator first, TIterator last)
Add.
Definition histogram.h:345
void operator()(TIterator first, TIterator last)
operator ()
Definition histogram.h:366
histogram(const histogram &other)
Copy constructor.
Definition histogram.h:296
void operator()(key_type key)
operator ()
Definition histogram.h:357
Histogram with a compile time start index.
Definition histogram.h:141
void operator()(key_type key)
operator ()
Definition histogram.h:233
void add(key_type key)
Add.
Definition histogram.h:212
value_type operator[](key_type key) const
operator []
Definition histogram.h:250
void add(TIterator first, TIterator last)
Add.
Definition histogram.h:221
histogram(TIterator first, TIterator last)
Constructor.
Definition histogram.h:163
histogram()
Constructor.
Definition histogram.h:154
histogram & operator=(const histogram &rhs)
Copy assignment.
Definition histogram.h:190
void operator()(TIterator first, TIterator last)
operator ()
Definition histogram.h:242
histogram(const histogram &other)
Copy constructor.
Definition histogram.h:172
Definition reference_flat_map.h:216
Base for histograms.
Definition histogram.h:52
const_iterator end() const
End of the histogram.
Definition histogram.h:80
const_iterator cend() const
End of the histogram.
Definition histogram.h:88
const_iterator cbegin() const
Beginning of the histogram.
Definition histogram.h:72
size_t count() const
Count of items in the histogram.
Definition histogram.h:120
const_iterator begin() const
Beginning of the histogram.
Definition histogram.h:64
void clear()
Clear the histogram.
Definition histogram.h:96
ETL_CONSTEXPR size_t size() const
Size of the histogram.
Definition histogram.h:104
ETL_CONSTEXPR size_t max_size() const
Max size of the histogram.
Definition histogram.h:112
Histogram for sparse keys.
Definition histogram.h:389
ETL_CONSTEXPR size_t max_size() const
Max size of the histogram.
Definition histogram.h:569
const_iterator begin() const
Beginning of the histogram.
Definition histogram.h:464
sparse_histogram(const sparse_histogram &other)
Copy constructor.
Definition histogram.h:424
const_iterator end() const
End of the histogram.
Definition histogram.h:480
void clear()
Clear the histogram.
Definition histogram.h:553
void add(TIterator first, TIterator last)
Add.
Definition histogram.h:505
const value_type & operator[](const key_type &key) const
operator []
Definition histogram.h:534
const_iterator cbegin() const
Beginning of the histogram.
Definition histogram.h:472
void operator()(const key_type &key)
operator ()
Definition histogram.h:517
sparse_histogram & operator=(const sparse_histogram &rhs)
Copy assignment.
Definition histogram.h:442
size_t size() const
Size of the histogram.
Definition histogram.h:561
sparse_histogram(TIterator first, TIterator last)
Constructor.
Definition histogram.h:416
sparse_histogram()
Constructor.
Definition histogram.h:410
void add(const key_type &key)
Add.
Definition histogram.h:496
void operator()(TIterator first, TIterator last)
operator ()
Definition histogram.h:526
const_iterator cend() const
End of the histogram.
Definition histogram.h:488
size_t count() const
Count of items in the histogram.
Definition histogram.h:577
ETL_CONSTEXPR14 T accumulate(TIterator first, TIterator last, T sum)
Definition algorithm.h:2284
Definition flat_map.h:1142
Definition integral_limits.h:518
bitset_ext
Definition absolute.h:40
unary_function
Definition functional.h:182