Skip to content

bdz2 #9

Open
l1sok wants to merge 1 commit intoSergeyBalabaev:mainfrom
l1sok:main
Open

bdz2 #9
l1sok wants to merge 1 commit intoSergeyBalabaev:mainfrom
l1sok:main

Conversation

@l1sok
Copy link

@l1sok l1sok commented Jun 1, 2025

Радионова ИВТ-23

@okuroshi okuroshi self-requested a review June 1, 2025 19:31
Copy link
Collaborator

@okuroshi okuroshi left a comment

Choose a reason for hiding this comment

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

Исправь stylecode. Найди какой тебе больше нравится и используй его, также приложи ссылку на него. Добавь тесты на кейсы, когда передается null и другие случаи, с этим кейсом. И другие замечания тоже

* @brief Освобождает память узла и его ключа/значения
* @param map указатель на структуру Map
* @param node узел для освобождения */
static void free_node(Map *map, Node *node) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

проверки на null от map нет


clean:
rm -f *.o $(LIB_NAME) $(TEST_EXEC)
touch clean No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

пропустил \n

* @brief Возвращает количество элементов в Map
* @param map указатель на структуру Map
* @return количество элементов в Map */
size_t map_size(const Map *map) { return map->size; } No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

пропустил \n


#ifdef __cplusplus
}
#endif No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

пропустил \n

RUN_TEST(test_map_with_string_keys);

return UNITY_END();
} No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

пропустил \n

* @brief Освобождает ресурсы, занятые Map
* @param map указатель на структуру Map
* @note Удаляет все узлы и освобождает память ключей/значений, если указаны соответствующие функции */
void map_free(Map *map) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

проверки на null

* @param free_key функция освобождения памяти ключа (может быть NULL)
* @param free_value функция освобождения памяти значения (может быть NULL)
* @note Перед использованием Map должна быть инициализирована этой функцией */
void map_init(Map *map,
Copy link
Collaborator

Choose a reason for hiding this comment

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

проверки на null

* @brief Восстанавливает свойства красно-черного дерева после удаления
* @param map указатель на структуру Map
* @param node узел, с которого начинается восстановление */
static void fix_delete(Map *map, Node *node) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

проверки на null

* @brief Выполняет левый поворот вокруг узла
* @param map указатель на структуру Map
* @param node узел, вокруг которого выполняется поворот */
static void rotate_left(Map *map, Node *node) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

проверки на null

* @param color цвет узла
* @param parent родительский узел
* @return указатель на созданный узел или NULL при ошибке выделения памяти */
static Node *create_node(void *key, void *value, Color color, Node *parent) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

проверки на null

while (node != map->root && node->parent->color == RED) {
Node *uncle;
if (node->parent == node->parent->parent->left) {
uncle = node->parent->parent->right;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Название uncle переменной выглядит логично, если воспринимать дерево, как мама, папа, ребенок, однако это просто способ понятней объяснить работу этой структуры. Попробуй придумать другое понятное название

successor->color = node->color;
}

if (original_color == BLACK) { fix_delete(map, child ? child : (node->parent ? node->parent : NULL)); }
Copy link
Collaborator

Choose a reason for hiding this comment

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

codestyle

node->right->parent = successor;
}

if (!node->parent) { map->root = successor; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

codestyle

}

if (!node->parent) { map->root = successor; }
else if (node == node->parent->left) { node->parent->left = successor; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

codestyle


if (!node->parent) { map->root = successor; }
else if (node == node->parent->left) { node->parent->left = successor; }
else { node->parent->right = successor; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

codestyle

else if (node == node->parent->left) { node->parent->left = child; }
else { node->parent->right = child; }

if (child) { child->parent = node->parent; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

codestyle

if (child) { child->parent = node->parent; }
} else if (!node->right) {
child = node->left;
if (!node->parent) { map->root = child; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

codestyle

#endif
#include <stdbool.h>

typedef enum { RED, BLACK } Color;
Copy link
Collaborator

Choose a reason for hiding this comment

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

codestyle

#endif
#include <stdbool.h>

typedef enum { RED, BLACK } Color;
Copy link
Collaborator

Choose a reason for hiding this comment

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

У тебя есть enum для цветой. Т.к были замечание по null, то добавь еще обработку других ошибок и также, чтобы код ошибки не был магическим числом

@@ -0,0 +1,43 @@
#pragma once
#ifdef __cplusplus
extern "C" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Для чего здесь это, если ты и так собираешь под C ?

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.

2 participants