From 79cf5bc0da8b3918ac218215605703e03bc96cad Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 5 Dec 2023 13:20:43 +0300 Subject: [PATCH 1/2] fixed --- src/files/Planner/Supervisor.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/files/Planner/Supervisor.h b/src/files/Planner/Supervisor.h index 1114c058..e3d91d6b 100644 --- a/src/files/Planner/Supervisor.h +++ b/src/files/Planner/Supervisor.h @@ -157,14 +157,12 @@ public: for (auto& empty : emptyKeys) sortedByKernelNeeds.erase(empty); + vector toDel; // проверяем нет ли завершившихся задач - for (auto it = activeTaskSet.begin(); it != activeTaskSet.end(); ) + for (auto& task : activeTaskSet) { - T* task = *(it); - if (task->Check()) { - it++; - activeTaskSet.erase(task); + toDel.push_back(task); activeTasks--; done++; busyKernels -= task->getKernels(); @@ -172,11 +170,12 @@ public: buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n"; task->copyResults(pathRes); - continue; } - it++; } + for (auto& del : toDel) + activeTaskSet.erase(del); + if (oldActiveTasks != activeTasks) printf("done %ld / %ld\n", done, this->getLength()); } -- 2.49.1 From 0bd2d3fe369f6c2f5a2b92c5c28d48abfdd29605 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 5 Dec 2023 14:08:31 +0300 Subject: [PATCH 2/2] improved String --- src/files/Planner/String.h | 209 +++++-------------------------------- 1 file changed, 27 insertions(+), 182 deletions(-) diff --git a/src/files/Planner/String.h b/src/files/Planner/String.h index f6d6315e..f6d7ee0c 100644 --- a/src/files/Planner/String.h +++ b/src/files/Planner/String.h @@ -4,223 +4,68 @@ #include #include #include +#include class String { friend String operator+(const String& a, const String& b); - long length; - char* body; + string body; + public: - String() { - length = 0; - body = new char[1]; - body[0] = '\0'; - } + String() { body = ""; } + String(const char* s) { body = s; } - String(const char* s) { - length = (long)strlen(s); - body = new char[length + 1]; - for (long i = 0; i < length; ++i) - body[i] = s[i]; - body[length] = '\0'; - } String(const char* s, char ps) { - length = (long)strlen(s); - body = new char[length + 1]; - for (long i = 0; i < length; ++i) { + body = s; + for (long i = 0; i < getLength(); ++i) body[i] = (s[i] == ps) ? '\n' : s[i]; - } - body[length] = '\0'; - } - ~String() { - if (body != NULL) { - delete[] body; - } - } - void println() const { - printf("[%s]\n", body); - } - void addChar(char c) { - char* buf = new char[length + 2]; - for (long i = 0; i < length; ++i) { - buf[i] = body[i]; - } - buf[length] = c; - - length++; - //-- - buf[length] = '\0'; - delete[] body; - body = buf; - buf = NULL; - } - char* getCharArray() const { - return body; } + String(int s) { body = to_string(s); } + String(long s) { body = to_string(s); } + String(long long s) { body = to_string(s); } - String(int s) { - length = 0; - body = new char[1]; - body[0] = '\0'; - if (s >= 0) { - int s_ = s; - int size = 1; - while (s_ >= 10) { - s_ = s_ / 10; - size++; - } - length = size; - body = new char[size + 1]; - sprintf(body, "%d", s); - } - } - - String(long s) : String((long long)s) { } - - String(long long s) { - length = 0; - body = new char[1]; - body[0] = '\0'; - if (s >= 0) { - long long s_ = s; - long size = 1; - while (s_ >= 10) { - s_ = s_ / 10; - size++; - } - length = size; - body = new char[size + 1]; - sprintf(body, "%lld", s); - } - } + void println() const { printf("[%s]\n", body.c_str()); } + void addChar(char c) { body += c; } + const char* getCharArray() const { return body.c_str(); } + const string& getBody() const { return body; } + size_t getLength() const { return body.size(); } + bool isEmpty() const { return body.size() != 0; } + bool contains(const String& s) const { return body.find(s.getBody()) != string::npos; } + bool operator==(const String& s) const { return body == s.getBody(); } const String& operator=(const String& s) { - if (body != NULL) - delete[] body; - length = s.length; - body = new char[length + 1]; - for (long i = 0; i < length; ++i) - body[i] = s.body[i]; - body[length] = '\0'; + body = s.getBody(); return *this; } static String DQuotes(const String& s) { - String res; - res.length = s.length + 2; - res.body = new char[res.length + 1]; - res.body[0] = '"'; - res.body[res.length - 1] = '"'; - res.body[res.length] = '\0'; - for (long i = 0; i < s.length; ++i) - res.body[i + 1] = s.body[i]; - return res; + string tmp = '"' + s.getBody() + '"'; + return String(tmp.c_str()); } String Replace(char f, char t) { - String res; - res.length = length; - res.body = new char[length]; - res.body[length] = '\0'; - for (long i = 0; i < length; ++i) + String res(body.c_str()); + for (auto i = 0; i < getLength(); ++i) res.body[i] = (body[i] == f) ? t : body[i]; return res; } String Remove(char f) { String res; - for (long i = 0; i < length; ++i) { + for (auto i = 0; i < getLength(); ++i) if (body[i] != f) res.addChar(body[i]); - } - return res; - } - bool isEmpty() const { - return length == 0; - } - bool contains(const String& s) const { - bool res = false; - bool search_on = false; - if (s.isEmpty()) return true; - if (s.length > length) return false; - long k = 0; - long start = -1; - for (long i = 0; i < length; ++i) { - if (search_on) { - if (k < s.length) { - if (body[i] == s.body[k]) { - k++; - } - else { - //обрыв поиска. - search_on = false; - k = 0; - start = -1; - } - } - else { - //printf("starts with %ld", start); - return true; - } - } - else { - if (body[i] == s.body[0]) { - k = 1; - start = i; - search_on = true; - //printf("search started %d\n", start); - } - } - } - if (search_on) { - //printf("starts with %ld\n", start); - res = true; - } return res; } + String toUpper() { String res = String(this->getCharArray()); - for (long i = 0; i < length; ++i) + for (auto i = 0; i < getLength(); ++i) res.body[i] = toupper(body[i]); res.println(); return res; } - long getLength() { - return length; - } - bool operator==(const String& s) const { - if (length != s.length) return false; - for (long i = 0; i < length; ++i) { - if (body[i] != s.body[i]) return false; - } - return true; - } - /* регистр. - #include - #include - - int main(void) { - FILE * f; - int c; - - if ( ! ( f = fopen("file.txt", "r") ) ) - return -1; - - while ( ( c = fgetc(f) ) != EOF ) - putchar( isupper(c) ? tolower(c) : toupper(c) ); - - return ( fclose(f) ); - } - */ }; String operator+(const String& a, const String& b) { - String res = String(); - res.length = a.length + b.length; - res.body = new char[res.length + 1]; - for (long i = 0; i < a.length; ++i) - res.body[i] = a.body[i]; - for (long i = 0; i < b.length; ++i) - res.body[i + a.length] = b.body[i]; - res.body[res.length] = '\0'; - return res; + return String((a.getBody() + b.getBody()).c_str()); } \ No newline at end of file -- 2.49.1