Skip to content

Update main.cpp#1

Open
Keyplexex wants to merge 1 commit into
SkymeFactor:mainfrom
Keyplexex:main
Open

Update main.cpp#1
Keyplexex wants to merge 1 commit into
SkymeFactor:mainfrom
Keyplexex:main

Conversation

@Keyplexex

Copy link
Copy Markdown

No description provided.

@Rorikss Rorikss left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В целом, неплохая работа! Хорошо, что не "убежала" память, здорово, что пытались разделить логику. Правда, все еще есть куда расти, обратите внимание на замечания, особенно про разделение логики

Comment thread main.cpp
Comment on lines +5 to +10
const int MAX_LINE_LENGTH = 1024;
const int MAX_FILTER = 128;
const int MAX_CONTEXT_LENGTH = 128;
const int MAX_WORDS = 10000;

void parseArgs(int argc, char* argv[], char* inputPath, char* filterdb, char* outputPath) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

конечно, это не портит работоспособность кода, но я бы советовала Вам все же придерживаться кодстайла, к которому мы привыкали целый семестр. Все же так код становится более читаемым. Не вижу смысла в данной работе править вам кодстайл, но оставлю как замечание в начале

Comment thread main.cpp
}
}

char** readFilters(const char* filterdb, int& filterCount) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ссылка весит 8 байт, когда int-- 4. тут можно без ссылки

Comment thread main.cpp
std::strcpy(filters[filterCount++], line);
}

file.close();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно не закрывать сам бы закрылся
(тоже некритичное замечание)

Comment thread main.cpp
delete[] filters;
}

void processFile(const char* inputPath, const char* outputPath, char** filters, int filterCount) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хорошо, что вы решили разделить немноголо логику на функции, но конкретно эта слишком большая. Стоило бы разделить чтение, анализ файла и вывод

Comment thread main.cpp
Comment on lines +65 to +80
if (containsFilter(word, filters, filterCount, matchedFilter)) {
int len = strlen(word);
discardedSizes[discardedCount] = len;
std::strcpy(discardedWords[discardedCount], word);

for (int i = 0; i < filterCount; ++i) {
if (strcmp(filters[i], matchedFilter) == 0) {
filterUsage[i]++;
usedFilterIndex[discardedCount] = i;
break;
}
}
discardedCount++;
} else {
outputFile << word << " ";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот тут можно было бы проифать ваш else, сделать continue и избежать вложенности

Comment thread main.cpp
}
}

if (relevantCount > 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

инвертировать if

Comment thread main.cpp
Comment on lines +27 to +28
filters[filterCount] = new char[strlen(line) + 1];
std::strcpy(filters[filterCount++], line);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот, кстати, как будто не регисронезависимо

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants