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
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,14 @@ int main(int argc, char * argv[])
for (int i = 0; i < 2; i++)
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);
fmt::print(stderr, "ok\n");
......
......@@ -25,6 +25,9 @@ class Config
using ConstValueIterator = std::vector<String>::const_iterator;
std::vector<String> lines;
public :
std::size_t wordIndex{0};
std::size_t characterIndex{0};
String state{"NONE"};
......
......@@ -13,7 +13,7 @@ class SubConfig : public Config
private :
const BaseConfig & model;
int firstLineIndex{0};
std::size_t firstLineIndex{0};
private :
......
......@@ -2,6 +2,10 @@
SubConfig::SubConfig(BaseConfig & model) : model(model)
{
wordIndex = model.wordIndex;
characterIndex = model.characterIndex;
state = model.state;
history = model.history;
update();
}
......@@ -12,36 +16,47 @@ bool SubConfig::update()
if (currentLastLineIndex >= model.getNbLines()-1)
return false;
unsigned int newFirstLineIndex = firstLineIndex + 0.8*(currentLastLineIndex-firstLineIndex);
unsigned int newLastLineIndex = std::min(newFirstLineIndex + spanSize, model.getNbLines());
std::size_t newFirstLineIndex = spanSize/2 >= wordIndex ? 0 : wordIndex - spanSize/2;
std::size_t newLastLineIndex = std::min(newFirstLineIndex + spanSize, model.getNbLines());
unsigned int newLineNumber = newLastLineIndex - newFirstLineIndex;
if (getNbLines() < 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 firstToSave = getConstIterator(0, newFirstLineIndex, 0);
auto lastToSave = getConstIterator(0, currentLastLineIndex, 0);
while (firstToSave != lastToSave)
(*linesBegin++) = (*firstToSave++);
}
*linesBegin++ = *firstToSave++;
if (getNbLines() > newLineNumber)
resizeLines(newLineNumber);
{
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);
firstToSave = model.getConstIterator(0, currentLastLineIndex, 0);
lastToSave = model.getConstIterator(0, newLastLineIndex, 0);
while (firstToSave != lastToSave)
(*newlinesBegin++) = (*firstToSave++);
firstLineIndex = newFirstLineIndex;
*linesBegin++ = *firstToSave++;
} // If the two windows are the same, do nothing.
else if (firstLineIndex == newFirstLineIndex and currentLastLineIndex == newLastLineIndex)
{
}
else
{
util::myThrow("Update after a regression of wordIndex is not yet supported !");
}
firstLineIndex = newFirstLineIndex;
return true;
}
......
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