Skip to content

Conversation

@18thday
Copy link
Contributor

@18thday 18thday commented Dec 25, 2025

No description provided.

int64_t Addition(int a, int b) {
throw std::runtime_error{"Not implemented"};
} No newline at end of file
return (int64_t)a + b;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

c-style cast не уместен, static_cast

int count_repeat = 1;

std::string tmp;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

зачем все эти пустые строки?

if (array[i] == prev_ch) {
if (array[i] != ' ') {
++count_repeat;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

это достаточно короткая ветвь, поэтому добавить строку присвоения из конца и continue, неудобно листать большой блок кода ниже

++count_repeat;
}
}
else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

и else убрать поскольку он станет лишним и уйдет уровень вложенности

if (f(vec[i])) {
res.push_back(i);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Два прохода, а если передана тяжелая функция предикат, не эффективно

}
}

return std::make_pair(min, max);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

примерно 3 лишних пустых строки


auto MinMax(const std::vector<int>& vec) {
if (vec.empty()) {
return std::make_pair(vec.end(),vec.end());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

нет пробела после запятой

res.push_back(vec[i + 1]);
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

два прохода не нужны

Copy link
Contributor Author

@18thday 18thday left a comment

Choose a reason for hiding this comment

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

  • не уместно используется C-style каст
  • местами используется постфиксный декремент инкремент вместо префиксного
  • разный стиль кода местами
  • неуместные лишние пустые строки
  • дублирование кода
  • часто неэффективные решения
  • const_cast UB

}

m_data.pop_back();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

две лишние пустые строки

}

const int& Stack::Top() const {
return (const_cast<Stack*>(this))->Top();
Copy link
Contributor Author

@18thday 18thday Jan 22, 2026

Choose a reason for hiding this comment

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

UB const_cast
когда метод в одну строку, особого смысла нет вызывать метод из метода

}

bool Stack::operator==(const Stack& other) const {
return this->m_data == other.m_data;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

использование this-> лишнее, так не нужно писать

size_t m_current_count;
};

RingBuffer::RingBuffer(size_t capacity) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

это все должно быть в списке инициализации

RingBuffer::RingBuffer(size_t capacity, int fill) : RingBuffer(capacity) {
std::fill(m_data.begin(), m_data.end(), fill);
m_end_index = m_data.size() - 1;
m_current_count = m_data.size();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

в данном случае это избыточный код, мы сначала создаем по умолчанию а потом ещё раз проходимся и заполняем, в данном случае тоже лучше использовать список инициализации, у вектора есть конструткор который аналогичные аргументы и заполняет контейнер одинаковыми элементами


bool RingBuffer::TryPush(int element) {
if (!Full()) {
Push(element);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

дважды проверка на !Full будет выполняться

m_end_index = (m_end_index + 1) % Capacity();

if (m_end_index == m_start_index) {
m_start_index = (m_start_index + 1) % Capacity();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

можно вынести в приватный метод если часто повторяется и принимать по ссылке idx

bool RingBuffer::TryPop(int& element) {
if (!Empty()) {
element = m_data[m_start_index];
Pop();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

дважды будет проверка !Empty

}

const int& RingBuffer::operator[](size_t index) const {
return (const_cast<RingBuffer*>(this))->operator[](index);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

UB const_cast, опять же, строка длиннее


for (size_t i = 0; i < Size(); ++i) {
vec[i] = m_data[(m_start_index + i + skip) % Capacity()];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

если в коде выше добавить skip = 0 можно вынести цикл

}
}

Queue::Queue(const std::vector<int>& vec) : Queue(vec.size()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

можно сконструировать напрямую m_output

}

Queue::Queue(std::initializer_list<int> il) : Queue(il.size()) {
std::reverse_copy(il.begin(), il.end(), std::back_inserter(m_output));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

можно сконструировать напрямую нужный вектор, без лишних действий

if (m_output.empty()) {
std::reverse_copy(m_input.cbegin(), m_input.cend(), std::back_inserter(m_output));
m_input.clear();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

это операция перекладыания элемментов может иметь понятное название и вынесена в отдельный приватный метод

}

const int& Queue::Front() const {
return (const_cast<Queue*>(this))->Front();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

UB const_cast для константного объекта

std::reverse_copy(other.m_output.cbegin(), other.m_output.cend(), std::back_inserter(value2));
std::copy(other.m_input.cbegin(), other.m_input.cend(), std::back_inserter(value2));

return value1 == value2;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

не оптимальное сравнение, мы знаем внутреннее устройство и можем сравнить без копирования, в данном случае это плохое решение

return Phasor(num, 0.0) / other;
}

Phasor Phasor::operator+=(const Phasor& other) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

почему возвращается не ссылка на текущий объект, а копия?

double phase = std::atan2(m_imag, m_real);

if (std::fabs(phase - (-std::numbers::pi)) < 1e-9) {
return std::numbers::pi;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

можно ввести using внутри класса, чтобы писать pi

double Phasor::Phase() const {
double phase = std::atan2(m_imag, m_real);

if (std::fabs(phase - (-std::numbers::pi)) < 1e-9) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

пороговое значение лучше задать константой, чтобы можно было менять в одном месте

@18thday
Copy link
Contributor Author

18thday commented Jan 22, 2026

@GametestAccount

  • не используются список инициализации у конструкторов
  • использование this->
  • UB const_cast
  • неоптимальное сравнение с копированием в Queue
  • некорректные сигнатуры операторов составного присваивания в Phasor

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.

1 participant