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;
299 start_index = other.start_index;
308 this->accumulator = etl::move(other.accumulator);
309 start_index = other.start_index;
318 this->accumulator = rhs.accumulator;
319 start_index = rhs.start_index;
330 this->accumulator = etl::move(rhs.accumulator);
331 start_index = rhs.start_index;
342 ++this->accumulator[
static_cast<size_t>(key - start_index)];
348 template <
typename TIterator>
349 void add(TIterator first, TIterator last)
351 while (first != last)
369 template <
typename TIterator>
380 return this->accumulator[
static_cast<size_t>(key - start_index)];
385 key_type start_index;
391 template <
typename TKey,
typename TCount,
size_t Max_Size_>
400 ETL_STATIC_ASSERT(etl::is_integral<TCount>::value,
"Only integral count allowed");
402 static ETL_CONSTANT
size_t Max_Size = Max_Size_;
404 typedef TKey key_type;
405 typedef TCount count_type;
406 typedef typename accumulator_type::value_type value_type;
419 template <
typename TIterator>
430 this->accumulator = other.accumulator;
439 accumulator = etl::move(other.accumulator);
448 accumulator = rhs.accumulator;
459 accumulator = etl::move(rhs.accumulator);
470 return accumulator.begin();
478 return accumulator.cbegin();
484 const_iterator
end()
const
486 return accumulator.end();
494 return accumulator.cend();
500 void add(
const key_type& key)
508 template <
typename TIterator>
509 void add(TIterator first, TIterator last)
511 while (first != last)
529 template <
typename TIterator>
540 static const value_type unused(key_type(), count_type(0));
544 if (itr != accumulator.end())
567 return accumulator.size();
583 count_type sum = count_type(0);
585 const_iterator itr = accumulator.begin();
587 while (itr != accumulator.end())
589 sum += (*itr).second;
593 return static_cast<size_t>(sum);
601 template <
typename TKey,
typename TCount,
size_t Max_Size_>
602 ETL_CONSTANT
size_t sparse_histogram<TKey, TCount, Max_Size_>::Max_Size;
histogram & operator=(const histogram &rhs)
Copy assignment.
Definition histogram.h:316
histogram(key_type start_index_, TIterator first, TIterator last)
Constructor.
Definition histogram.h:286
void add(key_type key)
Add.
Definition histogram.h:340
histogram(key_type start_index_)
Constructor.
Definition histogram.h:276
value_type operator[](key_type key) const
operator []
Definition histogram.h:378
void add(TIterator first, TIterator last)
Add.
Definition histogram.h:349
void operator()(TIterator first, TIterator last)
operator ()
Definition histogram.h:370
histogram(const histogram &other)
Copy constructor.
Definition histogram.h:296
void operator()(key_type key)
operator ()
Definition histogram.h:361
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:393
ETL_CONSTEXPR size_t max_size() const
Max size of the histogram.
Definition histogram.h:573
const_iterator begin() const
Beginning of the histogram.
Definition histogram.h:468
sparse_histogram(const sparse_histogram &other)
Copy constructor.
Definition histogram.h:428
const_iterator end() const
End of the histogram.
Definition histogram.h:484
void clear()
Clear the histogram.
Definition histogram.h:557
void add(TIterator first, TIterator last)
Add.
Definition histogram.h:509
const value_type & operator[](const key_type &key) const
operator []
Definition histogram.h:538
const_iterator cbegin() const
Beginning of the histogram.
Definition histogram.h:476
void operator()(const key_type &key)
operator ()
Definition histogram.h:521
sparse_histogram & operator=(const sparse_histogram &rhs)
Copy assignment.
Definition histogram.h:446
size_t size() const
Size of the histogram.
Definition histogram.h:565
sparse_histogram(TIterator first, TIterator last)
Constructor.
Definition histogram.h:420
sparse_histogram()
Constructor.
Definition histogram.h:414
void add(const key_type &key)
Add.
Definition histogram.h:500
void operator()(TIterator first, TIterator last)
operator ()
Definition histogram.h:530
const_iterator cend() const
End of the histogram.
Definition histogram.h:492
size_t count() const
Count of items in the histogram.
Definition histogram.h:581
ETL_CONSTEXPR14 T accumulate(TIterator first, TIterator last, T sum)
Definition algorithm.h:2321
Definition flat_map.h:1279
Definition integral_limits.h:517
unary_function
Definition functional.h:182