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

Update of SubConfig now related to wordIndex

parent abb71284
Branches
No related tags found
No related merge requests found
...@@ -16,6 +16,14 @@ int main(int argc, char * argv[]) ...@@ -16,6 +16,14 @@ int main(int argc, char * argv[])
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
configs.emplace_back(config); configs.emplace_back(config);
configs[0].wordIndex = 2000;
configs[0].update();
configs[0].wordIndex = 0;
configs[0].update();
configs[0].update();
configs[0].update();
configs[0].print(stdout); configs[0].print(stdout);
fmt::print(stderr, "ok\n"); fmt::print(stderr, "ok\n");
......
...@@ -25,6 +25,9 @@ class Config ...@@ -25,6 +25,9 @@ class Config
using ConstValueIterator = std::vector<String>::const_iterator; using ConstValueIterator = std::vector<String>::const_iterator;
std::vector<String> lines; std::vector<String> lines;
public :
std::size_t wordIndex{0}; std::size_t wordIndex{0};
std::size_t characterIndex{0}; std::size_t characterIndex{0};
String state{"NONE"}; String state{"NONE"};
......
...@@ -13,7 +13,7 @@ class SubConfig : public Config ...@@ -13,7 +13,7 @@ class SubConfig : public Config
private : private :
const BaseConfig & model; const BaseConfig & model;
int firstLineIndex{0}; std::size_t firstLineIndex{0};
private : private :
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
SubConfig::SubConfig(BaseConfig & model) : model(model) SubConfig::SubConfig(BaseConfig & model) : model(model)
{ {
wordIndex = model.wordIndex;
characterIndex = model.characterIndex;
state = model.state;
history = model.history;
update(); update();
} }
...@@ -12,36 +16,47 @@ bool SubConfig::update() ...@@ -12,36 +16,47 @@ bool SubConfig::update()
if (currentLastLineIndex >= model.getNbLines()-1) if (currentLastLineIndex >= model.getNbLines()-1)
return false; return false;
unsigned int newFirstLineIndex = firstLineIndex + 0.8*(currentLastLineIndex-firstLineIndex); std::size_t newFirstLineIndex = spanSize/2 >= wordIndex ? 0 : wordIndex - spanSize/2;
unsigned int newLastLineIndex = std::min(newFirstLineIndex + spanSize, model.getNbLines()); std::size_t newLastLineIndex = std::min(newFirstLineIndex + spanSize, model.getNbLines());
unsigned int newLineNumber = newLastLineIndex - newFirstLineIndex; unsigned int newLineNumber = newLastLineIndex - newFirstLineIndex;
if (getNbLines() < newLineNumber) if (getNbLines() < newLineNumber)
resizeLines(newLineNumber); resizeLines(newLineNumber);
// The two windows are disjoint, we must copy every value from model
if (currentLastLineIndex <= newFirstLineIndex or newLastLineIndex <= firstLineIndex)
{
auto linesBegin = getIterator(0, firstLineIndex, 0);
auto firstToSave = model.getConstIterator(0, newFirstLineIndex, 0);
auto lastToSave = model.getConstIterator(0, newLastLineIndex, 0);
while (firstToSave != lastToSave)
*linesBegin++ = *firstToSave++;
} // The new window is a bit shifted to the write, we will keep the lasts elements from old window
else if (currentLastLineIndex > newFirstLineIndex and currentLastLineIndex < newLastLineIndex)
{ {
auto linesBegin = getIterator(0, firstLineIndex, 0); auto linesBegin = getIterator(0, firstLineIndex, 0);
auto firstToSave = getConstIterator(0, newFirstLineIndex, 0); auto firstToSave = getConstIterator(0, newFirstLineIndex, 0);
auto lastToSave = getConstIterator(0, currentLastLineIndex, 0); auto lastToSave = getConstIterator(0, currentLastLineIndex, 0);
while (firstToSave != lastToSave) while (firstToSave != lastToSave)
(*linesBegin++) = (*firstToSave++); *linesBegin++ = *firstToSave++;
}
if (getNbLines() > newLineNumber) firstToSave = model.getConstIterator(0, currentLastLineIndex, 0);
resizeLines(newLineNumber); lastToSave = model.getConstIterator(0, newLastLineIndex, 0);
{
unsigned int nbLinesCopied = currentLastLineIndex - newFirstLineIndex;
auto newlinesBegin = getIterator(0, firstLineIndex+nbLinesCopied, 0);
auto firstToSave = model.getConstIterator(0, currentLastLineIndex, 0);
auto lastToSave = model.getConstIterator(0, newLastLineIndex, 0);
while (firstToSave != lastToSave) while (firstToSave != lastToSave)
(*newlinesBegin++) = (*firstToSave++); *linesBegin++ = *firstToSave++;
} // If the two windows are the same, do nothing.
firstLineIndex = newFirstLineIndex; else if (firstLineIndex == newFirstLineIndex and currentLastLineIndex == newLastLineIndex)
{
} }
else
{
util::myThrow("Update after a regression of wordIndex is not yet supported !");
}
firstLineIndex = newFirstLineIndex;
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment