#include "histogram.h" #include #include template void histogram::add(const T& inst) { freqtable[inst]++; } template void histogram::compile() { distribution.clear(); int max = 0; for (auto& it : freqtable) { max += it.second; distribution.emplace(max, it.first); } freqtable.clear(); } template const T& histogram::next() const { int max = distribution.rbegin()->first; int r = rand() % max; return distribution.upper_bound(r)->second; } template void histogram::print() const { for (auto& freqpair : freqtable) { std::cout << freqpair.first << ": " << freqpair.second << std::endl; } } template class histogram ;