Revert "All necessary files were removed"#1
Conversation
This reverts commit df715fe.
rfrolov
left a comment
There was a problem hiding this comment.
Здравствуйте, Арсений.
Домашнее задание удовлетворяет ТЗ. Текст понятен, читается легко. Очень хорошо что реализованы тесты.
По реализации есть замечания/предложения, которые отметил в коде.
|
|
||
| rIpStr.append(input.at(0)); | ||
|
|
||
| for(std::vector<std::string>::const_iterator ip_part = input.cbegin() + 1; ip_part != input.cend(); ++ip_part) |
There was a problem hiding this comment.
Красивее сделать объявление ip_part через auto:
for(auto ip_part = input.cbegin() + 1; ip_part != input.cend(); ++ip_part)
There was a problem hiding this comment.
или через range for:
for (const auto& ip_part: input)
| namespace filtering { | ||
|
|
||
| using addressList = std::vector<std::vector<std::string>>; | ||
|
|
There was a problem hiding this comment.
По тексту много где повторяется std::vectorstd::string
Предлагаю ввести алиас через using этого типа.
There was a problem hiding this comment.
Это общепринято. Если есть какой-то алиас на типы из STL, то при чтении кода можно увидеть какой-нибудь vector и придется идти и разбираться что это за вектор, стандартный или нет.
|
|
||
| void showList(const addressList& input) | ||
| { | ||
| for (auto & ip: input) |
There was a problem hiding this comment.
Здесь и далее правильнее и безопаснее пользоваться квалификатором const.
for (const auto & ip: input).
| } | ||
|
|
||
| std::string suitableIp = getIp(ip); | ||
| rVecStr.push_back(suitableIp); |
There was a problem hiding this comment.
Здесь и далее код:
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, |
There was a problem hiding this comment.
Самописную лямбду можно заменить на std::greater<>.
Yukigaru
left a comment
There was a problem hiding this comment.
На мой взгляд, хранение ip адреса в строках - плохая идея. Стоит рассмотреть хранение обычных чисел.
Кроме этой фундаментальной проблемы, замечаний немного.
| namespace filtering { | ||
|
|
||
| using addressList = std::vector<std::vector<std::string>>; | ||
|
|
There was a problem hiding this comment.
Это общепринято. Если есть какой-то алиас на типы из 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) |
There was a problem hiding this comment.
или через 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) { |
There was a problem hiding this comment.
хранить и сравнивать строки очень неэффективно, когда речь идёт о простых числах.
стоило рассмотреть хранение октетов в integral типе
There was a problem hiding this comment.
с другой стороны, если все же сравнивается std::string и const char *, то можно сравнить напрямую, без strcmp
| { | ||
| if(lhs.size() == rhs.size()) | ||
| { | ||
| return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); |
There was a problem hiding this comment.
но что будет, если сравнить
1.111.1.1 и 1.11.111.1?
| #include <algorithm> | ||
| #include <tuple> | ||
| #include <stdexcept> | ||
| #include "filter_helper.h" |
|
Оценка ревью Романа. |
This reverts commit df715fe.