Skip to content
Snippets Groups Projects
Commit 52974429 authored by Franck Dary's avatar Franck Dary
Browse files

Fixed a bug related do undoing actions

parent fe396e89
No related branches found
No related tags found
No related merge requests found
......@@ -13,16 +13,18 @@ class LimitedArray
{
private :
std::vector<T> data;
std::vector< std::pair<T,bool> > data;
int nbElements;
int lastElementDataIndex;
int lastElementRealIndex;
T mask;
public :
LimitedArray(unsigned int limit) : data(limit)
LimitedArray(unsigned int limit, const T & mask) : data(limit)
{
clear();
this->mask = mask;
}
void clear()
......@@ -44,17 +46,21 @@ class LimitedArray
lastElementRealIndex++;
data[lastElementDataIndex] = elem;
data[lastElementDataIndex].first = elem;
}
const T & get(unsigned int index) const
{
return data[index % data.size()];
if (data[index % data.size()].second)
return mask;
return data[index % data.size()].first;
}
void set(unsigned int index, const T & value)
{
data[index % data.size()] = value;
data[index % data.size()].first = value;
data[index % data.size()].second = false;
}
int getLastIndex() const
......@@ -70,7 +76,7 @@ class LimitedArray
void printForDebug(FILE * out) const
{
for (int i = 0; i < std::min(nbElements,(int)data.size()); i++)
fprintf(out, "<%s>", data[i].c_str());
fprintf(out, "<%s>", data[i].first.c_str());
fprintf(out, "\n");
}
......
......@@ -401,6 +401,7 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na
}
auto deps = split(ba.data, '+');
for (auto s : deps)
if (!s.empty())
simpleBufferWrite(c, "GOV", "", std::stoi(s));
ba.data.clear();
};
......@@ -453,7 +454,9 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na
}
auto deps = split(ba.data, '+');
for (auto & dep : deps)
if (!dep.empty())
simpleBufferWrite(c, "LABEL", "", std::stoi(dep));
ba.data.clear();
};
auto appliable2 = [](Config & c, Action::BasicAction &)
{
......@@ -480,7 +483,9 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na
{
auto elems = split(ba.data);
for (auto elem : elems)
if (!elem.empty())
c.stackPush(std::stoi(elem));
ba.data.clear();
};
auto appliable4 = [](Config & c, Action::BasicAction &)
{
......@@ -530,6 +535,11 @@ std::vector<Action::BasicAction> ActionBank::str2sequence(const std::string & na
while (true)
{
if (c.pastActions.empty())
{
fprintf(stderr, "ERROR (%s) : trying to undo action while pastActions is empty. Aborting.\n", ERRINFO);
exit(1);
}
auto a = c.pastActions.pop();
if (ProgramParameters::debug)
fprintf(stderr, "Undoing... <%s><%s>\n", a.first.c_str(), a.second.name.c_str());
......
......@@ -5,7 +5,7 @@
#include "Action.hpp"
#include "ProgramOutput.hpp"
Config::Config(BD & bd, const std::string inputFilename) : bd(bd), hashHistory(30), pastActions(100)
Config::Config(BD & bd, const std::string inputFilename) : bd(bd), hashHistory(90), pastActions(100)
{
this->outputFile = nullptr;
this->stackHistory = -1;
......@@ -36,7 +36,7 @@ Config::Config(const Config & other) : bd(other.bd), hashHistory(other.hashHisto
this->file.reset(new File(*other.file.get()));
}
Config::Tape::Tape(const std::string & name, bool isKnown) : ref(ProgramParameters::readSize*4+1), hyp(ProgramParameters::readSize*4+1)
Config::Tape::Tape(const std::string & name, bool isKnown) : ref(ProgramParameters::readSize*4+1, Dict::unknownValueStr), hyp(ProgramParameters::readSize*4+1, std::make_pair(Dict::unknownValueStr, 0.0))
{
this->head = 0;
this->name = name;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment