Skip to content

bdz2 #9

Open
l1sok wants to merge 1 commit into
SergeyBalabaev:mainfrom
l1sok:main
Open

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

Conversation

@l1sok

@l1sok l1sok commented Jun 1, 2025

Copy link
Copy Markdown

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

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

@okuroshi okuroshi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread bdz2/Makefile

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

пропустил \n

Comment thread bdz2/bdz2.c
* @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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

пропустил \n

Comment thread bdz2/bdz2.h

#ifdef __cplusplus
}
#endif No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

пропустил \n

Comment thread bdz2/test_bdz2.c
RUN_TEST(test_map_with_string_keys);

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

пропустил \n

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

проверки на null

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

проверки на null

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

проверки на null

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

проверки на null

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

проверки на null

Comment thread bdz2/bdz2.c
while (node != map->root && node->parent->color == RED) {
Node *uncle;
if (node->parent == node->parent->parent->left) {
uncle = node->parent->parent->right;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread bdz2/bdz2.c
successor->color = node->color;
}

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codestyle

Comment thread bdz2/bdz2.c
node->right->parent = successor;
}

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codestyle

Comment thread bdz2/bdz2.c
}

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codestyle

Comment thread bdz2/bdz2.c

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codestyle

Comment thread bdz2/bdz2.c
else if (node == node->parent->left) { node->parent->left = child; }
else { node->parent->right = child; }

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codestyle

Comment thread bdz2/bdz2.c
if (child) { child->parent = node->parent; }
} else if (!node->right) {
child = node->left;
if (!node->parent) { map->root = child; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codestyle

Comment thread bdz2/bdz2.h
#endif
#include <stdbool.h>

typedef enum { RED, BLACK } Color;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codestyle

Comment thread bdz2/bdz2.h
#endif
#include <stdbool.h>

typedef enum { RED, BLACK } Color;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread bdz2/bdz2.h
@@ -0,0 +1,43 @@
#pragma once
#ifdef __cplusplus
extern "C" {

Copy link
Copy Markdown
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