Below is the file 'markov.cc' from this revision. You can also download the file.
#include <iostream> #include <deque> #include "markov.hh" using namespace std; MarkovState::MarkovState () { valid = false; } MarkovState::MarkovState (const deque<token_t> &q) { state = q; valid = true; } MarkovState::~MarkovState () { } void MarkovState::vdump () const { if (!valid) cout << " <invalid> "; cout << "[ "; for (deque<token_t>::const_iterator i=state.begin();i!=state.end();i++) { cout << *i << " "; } cout << "]"; } bool MarkovState::operator==(const MarkovState &s) { return s.state == state; } bool MarkovState::operator<(const MarkovState &s) { return s.state < state; } bool MarkovState::operator!=(const MarkovState &s) { return s.state != state; } MarkovModel::MarkovModel (const Stash &s, int length) { const vector<token_t> stash = s.get_stash (); deque<token_t> q; MarkovState last_state; size_t seen = 0; for (vector<token_t>::const_iterator i=stash.begin();i!=stash.end();i++) { seen++; q.push_back (*i); // cout << "token: " << *i << " : " << q.size() << endl; if (seen >= length) { MarkovState this_state(q); if (last_state.valid) { markov_pair p(last_state, this_state); edges[p]++; // cout << "edges go to " << edges[p] << endl; } last_state = MarkovState (q); q.pop_front(); } } cout << "debug: " << seen << endl; } void MarkovModel::Dump () { for (map<markov_pair, int>::const_iterator i=edges.begin(); i!=edges.end(); i++) { // cout << (*i).first.vdump() << " -> " << (*i).second.vdump() << endl; const markov_pair &p=(*i).first; token_t score=(*i).second; p.first.vdump(); cout << " :: "; p.second.vdump(); cout << " == " << score << endl; } } MarkovModel::~MarkovModel () { }