diff --git a/src/MarkovMatrix.cpp b/src/MarkovMatrix.cpp index 0214255..cd7c4ca 100644 --- a/src/MarkovMatrix.cpp +++ b/src/MarkovMatrix.cpp @@ -37,11 +37,11 @@ void MarkovMatrix::reset(int length) } -std::map MarkovMatrix::hiccup(std::string& previous) +std::unordered_map MarkovMatrix::hiccup(std::string& previous) { int size = previous.size(); int pos = std::max(size-this->length, 0); int len = size - pos; std::string before = previous.substr(pos, len); - return this->matrix[before]; + return this->matrix.at(before); } diff --git a/src/MarkovMatrix.hpp b/src/MarkovMatrix.hpp index 2b5627f..9bff329 100644 --- a/src/MarkovMatrix.hpp +++ b/src/MarkovMatrix.hpp @@ -1,7 +1,7 @@ #ifndef MARKOVMATRIX_HPP #define MARKOVMATRIX_HPP -#include +#include #include @@ -13,11 +13,11 @@ public: void feed(std::string& line); void reset(int length=0); // reset the matrix, length>0 -> set a new length - std::map hiccup(std::string& previous); + std::unordered_map hiccup(std::string& previous); private: int length; - std::map > matrix; + std::unordered_map > matrix; }; #endif diff --git a/src/SimpleMarkov.cpp b/src/SimpleMarkov.cpp index 8c2465c..e675085 100644 --- a/src/SimpleMarkov.cpp +++ b/src/SimpleMarkov.cpp @@ -66,7 +66,7 @@ std::string SimpleMarkov::regurgitateLine(std::string start) std::string next = ""; do { // get the possible next characters from the matrix - std::map possibles = this->matrix.hiccup(line); + std::unordered_map possibles = this->matrix.hiccup(line); // calculate sum of all possibilities int sum = 0; diff --git a/src/main.cpp b/src/main.cpp index 2d04dcd..7432abe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include #include "SimpleMarkov.hpp" + int main(int argc, char* argv[]) { if (argc > 5 || argc < 3) {