about summary refs log tree commit diff stats
path: root/histogram.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'histogram.cpp')
-rw-r--r--histogram.cpp46
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
6template <class T>
7void histogram<T>::add(const T& inst)
8{
9 freqtable[inst]++;
10}
11
12template <class T>
13void 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
27template <class T>
28const 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
36template <class T>
37void histogram<T>::print() const
38{
39 for (auto& freqpair : freqtable)
40 {
41 std::cout << freqpair.first << ": " << freqpair.second << std::endl;
42 }
43}
44
45template class histogram <std::string>;
46template class histogram <rawr::terminator>;