diff options
Diffstat (limited to 'histogram.cpp')
| -rw-r--r-- | histogram.cpp | 46 |
1 files changed, 0 insertions, 46 deletions
| diff --git a/histogram.cpp b/histogram.cpp deleted file mode 100644 index 77c5c3e..0000000 --- a/histogram.cpp +++ /dev/null | |||
| @@ -1,46 +0,0 @@ | |||
| 1 | #include "histogram.h" | ||
| 2 | #include "kgramstats.h" | ||
| 3 | #include <cstdlib> | ||
| 4 | #include <iostream> | ||
| 5 | |||
| 6 | template <class T> | ||
| 7 | void histogram<T>::add(const T& inst) | ||
| 8 | { | ||
| 9 | freqtable[inst]++; | ||
| 10 | } | ||
| 11 | |||
| 12 | template <class T> | ||
| 13 | void histogram<T>::compile() | ||
| 14 | { | ||
| 15 | distribution.clear(); | ||
| 16 | |||
| 17 | int max = 0; | ||
| 18 | for (auto& it : freqtable) | ||
| 19 | { | ||
| 20 | max += it.second; | ||
| 21 | distribution.emplace(max, it.first); | ||
| 22 | } | ||
| 23 | |||
| 24 | freqtable.clear(); | ||
| 25 | } | ||
| 26 | |||
| 27 | template <class T> | ||
| 28 | const T& histogram<T>::next() const | ||
| 29 | { | ||
| 30 | int max = distribution.rbegin()->first; | ||
| 31 | int r = rand() % max; | ||
| 32 | |||
| 33 | return distribution.upper_bound(r)->second; | ||
| 34 | } | ||
| 35 | |||
| 36 | template <class T> | ||
| 37 | void histogram<T>::print() const | ||
| 38 | { | ||
| 39 | for (auto& freqpair : freqtable) | ||
| 40 | { | ||
| 41 | std::cout << freqpair.first << ": " << freqpair.second << std::endl; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | template class histogram <std::string>; | ||
| 46 | template class histogram <rawr::terminator>; | ||
