summaryrefslogtreecommitdiff
path: root/library/globalFunctions.h
diff options
context:
space:
mode:
Diffstat (limited to 'library/globalFunctions.h')
-rw-r--r--library/globalFunctions.h30
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
bgstack15