Skip to content

Revert "All necessary files were removed"#1

Open
senyacherenkov wants to merge 1 commit intomasterfrom
review1
Open

Revert "All necessary files were removed"#1
senyacherenkov wants to merge 1 commit intomasterfrom
review1

Conversation

@senyacherenkov
Copy link
Owner

This reverts commit df715fe.

Copy link

@rfrolov rfrolov left a comment

Choose a reason for hiding this comment

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

Здравствуйте, Арсений.
Домашнее задание удовлетворяет ТЗ. Текст понятен, читается легко. Очень хорошо что реализованы тесты.
По реализации есть замечания/предложения, которые отметил в коде.


rIpStr.append(input.at(0));

for(std::vector<std::string>::const_iterator ip_part = input.cbegin() + 1; ip_part != input.cend(); ++ip_part)
Copy link

Choose a reason for hiding this comment

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

Красивее сделать объявление ip_part через auto:
for(auto ip_part = input.cbegin() + 1; ip_part != input.cend(); ++ip_part)

Copy link

Choose a reason for hiding this comment

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

или через range for:
for (const auto& ip_part: input)

namespace filtering {

using addressList = std::vector<std::vector<std::string>>;

Copy link

Choose a reason for hiding this comment

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

По тексту много где повторяется std::vectorstd::string
Предлагаю ввести алиас через using этого типа.

Copy link

Choose a reason for hiding this comment

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

Это общепринято. Если есть какой-то алиас на типы из STL, то при чтении кода можно увидеть какой-нибудь vector и придется идти и разбираться что это за вектор, стандартный или нет.


void showList(const addressList& input)
{
for (auto & ip: input)
Copy link

Choose a reason for hiding this comment

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

Здесь и далее правильнее и безопаснее пользоваться квалификатором const.
for (const auto & ip: input).

}

std::string suitableIp = getIp(ip);
rVecStr.push_back(suitableIp);
Copy link

Choose a reason for hiding this comment

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

Здесь и далее код:

std::string suitableIp = getIp(ip);
rVecStr.push_back(suitableIp);

можно написать более оптимально:
rVecStr.emplace_back(getIp(ip));


void lexicographRevSort(addressList& input)
{
std::sort(input.rbegin(), input.rend(),[](const std::vector<std::string> & lhs,
Copy link

Choose a reason for hiding this comment

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

Самописную лямбду можно заменить на std::greater<>.

Copy link

@Yukigaru Yukigaru left a comment

Choose a reason for hiding this comment

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

На мой взгляд, хранение ip адреса в строках - плохая идея. Стоит рассмотреть хранение обычных чисел.
Кроме этой фундаментальной проблемы, замечаний немного.

namespace filtering {

using addressList = std::vector<std::vector<std::string>>;

Copy link

Choose a reason for hiding this comment

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

Это общепринято. Если есть какой-то алиас на типы из STL, то при чтении кода можно увидеть какой-нибудь vector и придется идти и разбираться что это за вектор, стандартный или нет.


rIpStr.append(input.at(0));

for(std::vector<std::string>::const_iterator ip_part = input.cbegin() + 1; ip_part != input.cend(); ++ip_part)
Copy link

Choose a reason for hiding this comment

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

или через range for:
for (const auto& ip_part: input)

bool isByteFounded = false;
for (auto& ip_part: ip)
{
if (std::strcmp(ip_part.c_str(), byte1) == 0) {
Copy link

Choose a reason for hiding this comment

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

хранить и сравнивать строки очень неэффективно, когда речь идёт о простых числах.
стоило рассмотреть хранение октетов в integral типе

Copy link

Choose a reason for hiding this comment

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

с другой стороны, если все же сравнивается std::string и const char *, то можно сравнить напрямую, без strcmp

{
if(lhs.size() == rhs.size())
{
return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
Copy link

Choose a reason for hiding this comment

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

исп-е lexicompare - здорово

Copy link

Choose a reason for hiding this comment

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

но что будет, если сравнить
1.111.1.1 и 1.11.111.1?

#include <algorithm>
#include <tuple>
#include <stdexcept>
#include "filter_helper.h"
Copy link

Choose a reason for hiding this comment

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

лишние инклуды

@PetrLiutik
Copy link

Оценка ревью Романа.
С большинством замечаний/предложений Романа (rfrolov) согласен. Конечно можно было бы еще сделать замечание по использованию чисел для хранения и обработки ip-адресов вместо строк.

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.

4 participants