Below is the file 'markov.hh' from this revision. You can also download the file.
#ifndef __MARKOV_HH #define __MARKOV_HH #include "tokens.hh" #include <vector> #include <deque> #include <map> class MarkovState { public: std::deque<token_t> state; bool valid; MarkovState (); MarkovState (const std::deque<token_t> &); ~MarkovState (); bool operator==(const MarkovState &); bool operator!=(const MarkovState &); bool operator<(const MarkovState &); }; typedef std::pair< MarkovState, MarkovState > markov_pair; namespace __EXT__ { template <> struct hash<MarkovState> { size_t operator()(MarkovState __s) const { size_t rv=0; __EXT__::hash<int> h; for (std::deque<token_t>::const_iterator i=__s.state.begin(); i!=__s.state.end(); i++) { rv ^= h(*i); } return rv; } }; template <> struct hash<markov_pair> { size_t operator()(markov_pair __s) const { __EXT__::hash<MarkovState> h; size_t h1, h2; h1 = h(__s.first); h2 = h(__s.second); return h1 ^ (h2*h2); } }; } namespace std { template <> struct equal_to<markov_pair> { size_t operator()(markov_pair p1, markov_pair p2) { return p1.first == p2.first && p1.second == p2.second; } }; template <> struct less<markov_pair> { bool operator()(markov_pair p1, markov_pair p2) { if (p1.first < p2.first) { return true; } else if (p1.first != p2.first) { return false; } else { return p1.second < p2.second; } } }; } class MarkovModel { private: std::map<markov_pair, int > edges; public: MarkovModel (const Stash&, int); ~MarkovModel (); }; #endif