Browse Source

Fixes some compile errors and switched to gnu11 standard

tree_alloc
Cameron Weinfurt 1 year ago
parent
commit
09bacea6df
  1. 2
      Makefile
  2. 10
      tree_alloc.c

2
Makefile

@ -1,7 +1,7 @@
objs = main.o tree_alloc.o util.o
CC = clang
COMMON_FLAGS = -std=c11
COMMON_FLAGS = -std=gnu11
OUT_NAME = the_alloc
dev: CFLAGS= $(COMMON_FLAGS) -g -D UNIT_TESTS

10
tree_alloc.c

@ -188,7 +188,7 @@ void repair_after_remove(TreeAlloc **root_ptr, TreeAlloc *node) {
if (sibling->left->color == COLOR_BLACK && sibling->right->color == COLOR_BLACK) {
node->color = COLOR_BLACK;
sibling->color = COLOR_RED;
repair_after_remove(root_ptr, parent);
repair_after_remove(root_ptr, node->parent);
} else {
if (node->parent->left == node && sibling->right->color == COLOR_BLACK) {
rotate_right(root_ptr, sibling);
@ -196,7 +196,7 @@ void repair_after_remove(TreeAlloc **root_ptr, TreeAlloc *node) {
sibling->color = COLOR_RED;
sibling->right->color = COLOR_RED;
rotate_left(root_ptr, parent);
rotate_left(root_ptr, node->parent);
node->color = get_sibling(node->parent)->color = COLOR_BLACK;
} else if (node->parent->right == node && sibling->left->color == COLOR_BLACK) {
rotate_left(root_ptr, sibling);
@ -220,17 +220,17 @@ void remove_node(TreeAlloc **root_ptr, TreeAlloc *node) {
TreeAlloc *parent = node->parent;
if (!node->left) {
replace = node->right;
do_fix = node->color == COLOR_BLACK;
do_repair = node->color == COLOR_BLACK;
replace_node(root_ptr, node, replace);
} else if (!node->right) {
replace = node->left;
do_fix = node->color == COLOR_BLACK;
do_repair = node->color == COLOR_BLACK;
replace_node(root_ptr, node, replace);
} else {
TreeAlloc *tmp = node->right;
while (tmp->left) tmp = tmp->left;
replace = tmp->right;
do_fix = tmp == COLOR_BLACK;
do_repair = tmp->color == COLOR_BLACK;
if (tmp != node->right) {
replace_node(root_ptr, tmp, replace);
tmp->right = node->right;

Loading…
Cancel
Save