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

Avoiding loops at end of decoding

parent b6fda44a
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ class Config
std::vector<String> lines;
std::set<std::string> predicted;
int lastPoppedStack{-1};
protected :
......@@ -109,6 +110,7 @@ class Config
std::vector<long> extractContext(int leftBorder, int rightBorder, Dict & dict) const;
void addPredicted(const std::set<std::string> & predicted);
bool isPredicted(const std::string & colName) const;
int getLastPoppedStack() const;
};
#endif
......@@ -11,7 +11,6 @@ class TransitionSet
private :
std::vector<Transition> transitions;
std::optional<std::size_t> defaultAction;
public :
......
......@@ -139,9 +139,12 @@ Action Action::pushWordIndexOnStack()
config.popStack();
};
auto appliable = [](const Config &, const Action &)
auto appliable = [](const Config & config, const Action &)
{
return true;
if (config.hasStack(0) and config.getStack(0) == config.getWordIndex())
return false;
return (int)config.getWordIndex() != config.getLastPoppedStack();
};
return {Type::Push, apply, undo, appliable};
......
......@@ -309,6 +309,7 @@ void Config::addToStack(std::size_t index)
void Config::popStack()
{
lastPoppedStack = getStack(0);
stack.pop_back();
}
......@@ -491,3 +492,8 @@ bool Config::isPredicted(const std::string & colName) const
return predicted.count(colName);
}
int Config::getLastPoppedStack() const
{
return lastPoppedStack;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment