-
Notifications
You must be signed in to change notification settings - Fork 0
Денис Плотников #1
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: master
Are you sure you want to change the base?
Conversation
czertyaka
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.
Задание принято! Очень хорошая и подробная документация, ясный код. Исправление замечаний на ваше усмотрение.
| return 0u; | ||
|
|
||
| stack_entry_t* const entry = &g_table.entries[hstack]; | ||
| if (entry == NULL || entry->stack == NULL) |
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.
Статический анализатор подсказывает, что entry не может быть нулем (условие всегда ложно). По-моему, он прав
| return 0u; | ||
| // Если копировать доступное валидное: | ||
| //const unsigned int copy_size = (node->size < size) ? node->size : size; | ||
| void* payload = (void*)(node + 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.
Указатель может быть константым. Хорошее правило — делать константой все, что не должно меняться. Я бы тут сделал
const void* const payload = /**/;| * | ||
| * @ref stack_t | ||
| */ | ||
| const struct node* prev; |
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.
Мое субъективное мнение: если вам в вашем коде приходится кастить константный объект к мутабельному, изначально не стоило делать его константым.
| /** | ||
| * @brief Количество элементов в таблице. | ||
| * | ||
| * Определяет размер массива @ref stack_entries_table::entries . |
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.
| * Определяет размер массива @ref stack_entries_table::entries . | |
| * Определяет размер массива @ref stack_entries_table::entries. |
| if (g_table.entries != NULL) { | ||
| for (unsigned int i = 0; i < g_table.size; ++i) { | ||
| if (g_table.entries[i].reserved == 0) | ||
| return (int)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.
Формально должно быть сравнение с INT_MAX
|
|
||
| // Cвободного слота нет -> расширить таблицу минимум до (g_table.size + 1) | ||
| const unsigned int old_size = g_table.size; | ||
| if (table_ensure_capacity(old_size + 1) != 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.
Я бы предложил воспользоваться стратегией класса std::vector из C++ и увеличивать емкость в 2 раза.
| g_table.entries[slot].stack = NULL; // Стек пуст | ||
|
|
||
| // Вернуть индекс слота как hstack_t | ||
| return (hstack_t)slot; |
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.
Зачем выполнять преобразование между объектами с одним типом?
No description provided.