-
Notifications
You must be signed in to change notification settings - Fork 33
Мананов Данил #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Мананов Данил #21
Conversation
This reverts commit 5ba2b46.
| rhs.birth_date.year, | ||
| rhs.birth_date.month, | ||
| rhs.birth_date.day); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут несколько проблем:
- Кортеж таким образом не очень эффективно делать, поскольку создадуться копии, лучше использовать std::tie который использует ссылки
- Лучше написать отдельный оператор для даты и в данном случае использовать не каждое поле а сразу сравнение класса даты, поскольку там нет особенностей в поведении
- Действия с оценкой и курсом излишни, поскольку можно просто в левый операнд отправиль rhs.field, а в правый lhs.field в нужных местах
| } | ||
| os << "DEST"; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Дублирования конечно хотелось бы избежать
| for (size_t readIndex = 0; readIndex < array.size(); ++readIndex) { | ||
| if (predicate(array[readIndex])) { | ||
| if (writeIndex != readIndex) { | ||
| array[writeIndex] = std::move(array[readIndex]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
использование std::move не очень корректно, так как работа с фундаментальным типом, скопировать будет лучше
| //Итераторы ведут себя примерно также как указатели, но они могут быть и не указателями, а хоть чем. Это абстракция некая над указателем, если можно так сказать | ||
| */ | ||
|
|
||
| using IteratorsPairReturn = std::pair<std::vector<int>::const_iterator,std::vector<int>::const_iterator> ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- лишний пробел в конце, и можно было ограничится псевдонимом для итератора, так как он дублируется
- не хватает пробела после запятой
| } | ||
| else if (*iter >= *maxIt) { | ||
| maxIt = iter; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
проблемы с выравниванием кода
| os << "+"; | ||
| } else { | ||
| os << "-"; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в данном случае конечно используется тернарный оператор
| for (int i = from; i > to; i += step) { | ||
| rangedArray.push_back(i); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
дублирование кода
| } | ||
| else if (step < 0 && from > to) { | ||
| countSteps = (from - to - step - 1) / (-step); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно переписать с тернарным оператором при оъявлении
| outputArray.push_back(inputArray[i]); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не уверен в выгодности двух проходов
|
|
||
| size_t uniqueCount = 1; | ||
| for (size_t i = 1; i < size; ++i) { | ||
| if (inputArray[i] != inputArray[i-1]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не хватает пробелов вокруг оператора -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dsv9toy Данил, проверил первые 3 недели
- неплохой код, но местами много дублирования
- много ошибок по стилю кода, небрежность в выравнивании
| bool operator!=(const Stack& otherStack) const; | ||
|
|
||
|
|
||
| private: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше убрать дополнительный отступ у модификаторов доступа и сооветственно один уровень отступа у методов и полей
| std::vector<int> buffer_; | ||
| size_t oldestElement_ = 0; | ||
| size_t indexNextElem_ = 0; | ||
| size_t currentCountElem_ = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
несколько громоздкие названия, данное можно заменить на size_
| buffer_.resize(capacity); | ||
| oldestElement_ = 0; | ||
| indexNextElem_ = 0; | ||
| currentCountElem_ = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это должно быть все в списке инициализации
| buffer_[0] = initialValue; | ||
| indexNextElem_ = 1 % buffer_.capacity(); | ||
| currentCountElem_ = 1; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это плохо, можно было в списке инициализации вызвать соответствуеющийконструктор вектора, а тут достаточно объемный код, но дае еслитак, лучшеизбавится от else и лишней вложенности и поставить внтруи if return
| oldestElement_ = 0; | ||
| indexNextElem_ = 0; | ||
| currentCountElem_ = 0; | ||
| for (int value : init) Push(value); //Добавил range based, так как будто бы уютнее смотрится |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
аналогично, можно вызвать конструктор вектора от init
| indexNextElem_ = NextIndex(indexNextElem_); | ||
| } else { | ||
| buffer_[indexNextElem_] = value; | ||
| indexNextElem_ = NextIndex(indexNextElem_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в каждой из ветвей есть общий код, дублирование
| for (size_t i = 0; i < otherQueue.inputDat.size(); ++i) { | ||
| temp2.push_back(otherQueue.inputDat[i]); | ||
| } | ||
| return temp1 == temp2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зная устройство контейнера, лучше избежать копирования при сравнении, также реализовано с дублированием кода
| tempOutput.push_back(tempInput.back()); | ||
| tempInput.pop_back(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
неэффективный метод с копированием
| return outputDat.back(); | ||
| } | ||
|
|
||
| const int& Queue::Front() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
методы Front неконсистенты между собой, используют разные подходы
| Queue::Queue(std::initializer_list<int> initList) : inputDat(initList) {} | ||
|
|
||
| Queue::Queue(const std::stack<int>& stack) { | ||
| std::stack<int> temp = stack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужно тогда сразу принимать копию, иначе не понятно, что это не очень эффективный метод
| std::stack<int> temp = stack; | ||
| // Извлекаем элементы из стека в обратном порядке | ||
| while (!temp.empty()) { | ||
| inputDat.insert(inputDat.begin(), temp.top()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
производить вставку в начало вектора очень неэффективно, когда есть контейнер output
| } | ||
|
|
||
| Phasor operator/(const Phasor& phasor, double scalar) { | ||
| Phasor result = phasor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
может тогда Phasor принимать как копию?
18thday
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dsv9toy отметил следующие моменты, требующие исправления:
- использование тела конструктора вместо списка инициализации
- неэффективно сравнение в Queue с копированием
- неэффектривный метод Front с копированием в Queue
- неэффективный конструктор от стека в Queue
No description provided.