From 1412cb1abfe57f8d7c1e8a2e8e5ae9c7a1642462 Mon Sep 17 00:00:00 2001 From: pixhawk Date: Mon, 3 Jan 2011 07:37:32 +0100 Subject: [PATCH] Speeded up logfile compression from quadratic to near-linear complexity --- src/LogCompressor.cc | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/LogCompressor.cc b/src/LogCompressor.cc index 01c2f0201..fd394d985 100644 --- a/src/LogCompressor.cc +++ b/src/LogCompressor.cc @@ -125,7 +125,9 @@ void LogCompressor::run() file.reset(); QTextStream data(&file); int linecounter = 0; - while (!data.atEnd()) { + quint64 lastTimeIndex = 0; + while (!data.atEnd()) + { linecounter++; currentDataLine = linecounter; QString line = data.readLine(); @@ -140,7 +142,33 @@ void LogCompressor::run() value = "NaN"; } // Get matching output line - quint64 index = times->indexOf(time); + + // Constraining the search area might result in not finding a key, + // but it significantly reduces the time needed for the search + // setting a window of 1000 entries means that a 1 Hz data point + // can still be located + int offsetLimit = 200; + quint64 offset; + quint64 index = -1; + while (index == -1) + { + if (lastTimeIndex > offsetLimit) + { + offset = lastTimeIndex - offsetLimit; + } + else + { + offset = 0; + } + quint64 index = times->indexOf(time, offset); + if (index == -1) + { + qDebug() << "INDEX NOT FOUND DURING LOGFILE PROCESSING, RESTARTING SEARCH"; + // FIXME Reset and start without offset heuristic again + offsetLimit+=1000; + } + } + lastTimeIndex = index; QString outLine = outLines->at(index); QStringList outParts = outLine.split(separator); // Replace measurement placeholder with current value -- 2.22.0