Merge pull request 'fixed' (#3) from planner_improve into main
Reviewed-on: http://alex-freenas.ddns.net:3000/M/VisualSapfor/pulls/3
This commit was merged in pull request #3.
This commit is contained in:
@@ -4,223 +4,68 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class String {
|
class String {
|
||||||
friend String operator+(const String& a, const String& b);
|
friend String operator+(const String& a, const String& b);
|
||||||
long length;
|
string body;
|
||||||
char* body;
|
|
||||||
public:
|
public:
|
||||||
String() {
|
String() { body = ""; }
|
||||||
length = 0;
|
String(const char* s) { body = s; }
|
||||||
body = new char[1];
|
|
||||||
body[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
String(const char* s, char ps) {
|
||||||
length = (long)strlen(s);
|
body = s;
|
||||||
body = new char[length + 1];
|
for (long i = 0; i < getLength(); ++i)
|
||||||
for (long i = 0; i < length; ++i) {
|
|
||||||
body[i] = (s[i] == ps) ? '\n' : s[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) {
|
void println() const { printf("[%s]\n", body.c_str()); }
|
||||||
length = 0;
|
void addChar(char c) { body += c; }
|
||||||
body = new char[1];
|
const char* getCharArray() const { return body.c_str(); }
|
||||||
body[0] = '\0';
|
const string& getBody() const { return body; }
|
||||||
if (s >= 0) {
|
size_t getLength() const { return body.size(); }
|
||||||
int s_ = s;
|
bool isEmpty() const { return body.size() != 0; }
|
||||||
int size = 1;
|
bool contains(const String& s) const { return body.find(s.getBody()) != string::npos; }
|
||||||
while (s_ >= 10) {
|
bool operator==(const String& s) const { return body == s.getBody(); }
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const String& operator=(const String& s) {
|
const String& operator=(const String& s) {
|
||||||
if (body != NULL)
|
body = s.getBody();
|
||||||
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';
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String DQuotes(const String& s) {
|
static String DQuotes(const String& s) {
|
||||||
String res;
|
string tmp = '"' + s.getBody() + '"';
|
||||||
res.length = s.length + 2;
|
return String(tmp.c_str());
|
||||||
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 Replace(char f, char t) {
|
String Replace(char f, char t) {
|
||||||
String res;
|
String res(body.c_str());
|
||||||
res.length = length;
|
for (auto i = 0; i < getLength(); ++i)
|
||||||
res.body = new char[length];
|
|
||||||
res.body[length] = '\0';
|
|
||||||
for (long i = 0; i < length; ++i)
|
|
||||||
res.body[i] = (body[i] == f) ? t : body[i];
|
res.body[i] = (body[i] == f) ? t : body[i];
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
String Remove(char f) {
|
String Remove(char f) {
|
||||||
String res;
|
String res;
|
||||||
for (long i = 0; i < length; ++i) {
|
for (auto i = 0; i < getLength(); ++i)
|
||||||
if (body[i] != f)
|
if (body[i] != f)
|
||||||
res.addChar(body[i]);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
String toUpper() {
|
String toUpper() {
|
||||||
String res = String(this->getCharArray());
|
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.body[i] = toupper(body[i]);
|
||||||
res.println();
|
res.println();
|
||||||
return res;
|
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 <stdio.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
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 operator+(const String& a, const String& b) {
|
||||||
String res = String();
|
return String((a.getBody() + b.getBody()).c_str());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
@@ -157,14 +157,12 @@ public:
|
|||||||
for (auto& empty : emptyKeys)
|
for (auto& empty : emptyKeys)
|
||||||
sortedByKernelNeeds.erase(empty);
|
sortedByKernelNeeds.erase(empty);
|
||||||
|
|
||||||
|
vector<T*> toDel;
|
||||||
// проверяем нет ли завершившихся задач
|
// проверяем нет ли завершившихся задач
|
||||||
for (auto it = activeTaskSet.begin(); it != activeTaskSet.end(); )
|
for (auto& task : activeTaskSet)
|
||||||
{
|
{
|
||||||
T* task = *(it);
|
|
||||||
|
|
||||||
if (task->Check()) {
|
if (task->Check()) {
|
||||||
it++;
|
toDel.push_back(task);
|
||||||
activeTaskSet.erase(task);
|
|
||||||
activeTasks--;
|
activeTasks--;
|
||||||
done++;
|
done++;
|
||||||
busyKernels -= task->getKernels();
|
busyKernels -= task->getKernels();
|
||||||
@@ -172,11 +170,12 @@ public:
|
|||||||
|
|
||||||
buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
|
buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
|
||||||
task->copyResults(pathRes);
|
task->copyResults(pathRes);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
it++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& del : toDel)
|
||||||
|
activeTaskSet.erase(del);
|
||||||
|
|
||||||
if (oldActiveTasks != activeTasks)
|
if (oldActiveTasks != activeTasks)
|
||||||
printf("done %ld / %ld\n", done, this->getLength());
|
printf("done %ld / %ld\n", done, this->getLength());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user