diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 16:55:14 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 16:55:14 +0200 |
commit | 222024f07e505617aec93dc4837be2be27d18856 (patch) | |
tree | c40f400baa6cf1d047205359f80c2b8f74a2b507 /library/globalFunctions.h | |
parent | 1.12 (diff) | |
download | FreeFileSync-222024f07e505617aec93dc4837be2be27d18856.tar.gz FreeFileSync-222024f07e505617aec93dc4837be2be27d18856.tar.bz2 FreeFileSync-222024f07e505617aec93dc4837be2be27d18856.zip |
1.13
Diffstat (limited to 'library/globalFunctions.h')
-rw-r--r-- | library/globalFunctions.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/library/globalFunctions.h b/library/globalFunctions.h index efbc42c7..add3c79d 100644 --- a/library/globalFunctions.h +++ b/library/globalFunctions.h @@ -4,6 +4,7 @@ #include <string> #include <algorithm> #include <vector> +#include <set> #include <wx/string.h> #include <fstream> #include <wx/stream.h> @@ -106,4 +107,33 @@ private: wxString errorMessage; }; + +//Note: the following lines are a performance optimization for deleting elements from a vector. It is incredibly faster to create a new +//vector and leave specific elements out than to delete row by row and force recopying of most elements for each single deletion (linear vs quadratic runtime) +template <class T> +void removeRowsFromVector(vector<T>& grid, const set<int>& rowsToRemove) +{ + vector<T> temp; + int rowToSkip = -1; //keep it an INT! + + set<int>::iterator rowToSkipIndex = rowsToRemove.begin(); + + if (rowToSkipIndex != rowsToRemove.end()) + rowToSkip = *rowToSkipIndex; + + for (int i = 0; i < int(grid.size()); ++i) + { + if (i != rowToSkip) + temp.push_back(grid[i]); + else + { + ++rowToSkipIndex; + if (rowToSkipIndex != rowsToRemove.end()) + rowToSkip = *rowToSkipIndex; + } + } + grid.swap(temp); +} + + #endif // GLOBALFUNCTIONS_H_INCLUDED |