diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-01-29 12:43:00 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-01-29 12:43:00 -0500 |
commit | b316e309559d7176af6cf0bb7dcd6dbaa83c01cd (patch) | |
tree | f21bd883ef7c4255a91d096ea105feaad135ee52 /histogram.cpp | |
parent | fd1e9d59694c8a6ba201d2cdffec50f4f590841d (diff) | |
download | rawr-ebooks-b316e309559d7176af6cf0bb7dcd6dbaa83c01cd.tar.gz rawr-ebooks-b316e309559d7176af6cf0bb7dcd6dbaa83c01cd.tar.bz2 rawr-ebooks-b316e309559d7176af6cf0bb7dcd6dbaa83c01cd.zip |
Rewrote how tokens are handled
A 'word' is now an object that contains a distribution of forms that word can take. For now, most word just contain one form, the canonical one. The only special use is currently hashtags. Malapropisms have been disabled because of compatibility issues and because an upcoming feature is planned to replace it.
Diffstat (limited to 'histogram.cpp')
-rw-r--r-- | histogram.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/histogram.cpp b/histogram.cpp new file mode 100644 index 0000000..6896146 --- /dev/null +++ b/histogram.cpp | |||
@@ -0,0 +1,34 @@ | |||
1 | #include "histogram.h" | ||
2 | #include <cstdlib> | ||
3 | |||
4 | template <class T> | ||
5 | void histogram<T>::add(const T& inst) | ||
6 | { | ||
7 | freqtable[inst]++; | ||
8 | } | ||
9 | |||
10 | template <class T> | ||
11 | void histogram<T>::compile() | ||
12 | { | ||
13 | distribution.clear(); | ||
14 | |||
15 | int max = 0; | ||
16 | for (auto& it : freqtable) | ||
17 | { | ||
18 | max += it.second; | ||
19 | distribution.emplace(max, it.first); | ||
20 | } | ||
21 | |||
22 | freqtable.clear(); | ||
23 | } | ||
24 | |||
25 | template <class T> | ||
26 | const T& histogram<T>::next() const | ||
27 | { | ||
28 | int max = distribution.rbegin()->first; | ||
29 | int r = rand() % max; | ||
30 | |||
31 | return distribution.upper_bound(r)->second; | ||
32 | } | ||
33 | |||
34 | template class histogram <std::string>; | ||