summary refs log tree commit diff stats
path: root/histogram.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2019-02-28 20:28:20 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2019-02-28 20:28:20 -0500
commitd7e934156858287cdb7597ad0dced97d4d279f2f (patch)
treee1822649bb449d972839bb5c8adfd6b1c51d652c /histogram.cpp
parentb85830e8a852392036a803b7f6bb417c28ff17c4 (diff)
downloadaspartame-d7e934156858287cdb7597ad0dced97d4d279f2f.tar.gz
aspartame-d7e934156858287cdb7597ad0dced97d4d279f2f.tar.bz2
aspartame-d7e934156858287cdb7597ad0dced97d4d279f2f.zip
Got it bot-ready!
Using C++ randomization now, along with an update to rawr-ebooks that allows it to do the same. Cleaned up the code here and there. Added in the twitter client and the config file reader. We can use librawr's histogram class now, so we don't need our own. Also why did we not name this bot "aspartame". It's a Sugar replacer. Hahaha. I'm Pink Diamond.
Diffstat (limited to 'histogram.cpp')
-rw-r--r--histogram.cpp44
1 files changed, 0 insertions, 44 deletions
diff --git a/histogram.cpp b/histogram.cpp deleted file mode 100644 index 38fca45..0000000 --- a/histogram.cpp +++ /dev/null
@@ -1,44 +0,0 @@
1#include "histogram.h"
2#include <cstdlib>
3#include <iostream>
4
5template <class T>
6void histogram<T>::add(const T& inst)
7{
8 freqtable[inst]++;
9}
10
11template <class T>
12void histogram<T>::compile()
13{
14 distribution.clear();
15
16 int max = 0;
17 for (auto& it : freqtable)
18 {
19 max += it.second;
20 distribution.emplace(max, it.first);
21 }
22
23 freqtable.clear();
24}
25
26template <class T>
27const T& histogram<T>::next() const
28{
29 int max = distribution.rbegin()->first;
30 int r = rand() % max;
31
32 return distribution.upper_bound(r)->second;
33}
34
35template <class T>
36void histogram<T>::print() const
37{
38 for (auto& freqpair : freqtable)
39 {
40 std::cout << freqpair.first << ": " << freqpair.second << std::endl;
41 }
42}
43
44template class histogram <unsigned long>;