improved Array: use std::vector

This commit is contained in:
2023-12-03 13:41:29 +03:00
parent 6b7bde1471
commit c4b8e2dd7a
8 changed files with 42 additions and 45 deletions

View File

@@ -38,18 +38,19 @@ public:
}
//-
void print() {
for (long i = 0; i < this->length; ++i)
this->elements[i]->print();
for (auto& elem : this->getElements())
elem->print();
}
void init(const char* fileName, int recordSize) {
state = WorkspacesCreation;
File* packedTasks = new File(fileName);
Text* lines = packedTasks->readLines();
this->length = lines->getLength() / recordSize;
this->elements = new T * [this->length];
const long length = lines->getLength() / recordSize;
int offset = 0;
for (int i = 0; i < this->length; ++i) {
this->elements[i] = new T(lines, offset);
for (int i = 0; i < length; ++i) {
this->add(new T(lines, offset));
offset += recordSize;
}
delete packedTasks;
@@ -59,13 +60,13 @@ public:
saveState();
long activeCount = 0;
//todo обязательно убрать отладочную печать.
printf("tasks count = %ld\n", this->length);
printf("tasks count = %ld\n", this->getLength());
while (this->state != End) {
// printf("state=%d\n", this->state);
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
activeCount = 0;
for (long i = 0; i < this->length; ++i) {
T* task = this->elements[i];
for (long i = 0; i < this->getLength(); ++i) {
T* task = this->get(i);
switch (this->state) {
case WorkspacesCreation:
if (task->getState() == Waiting) {