Browse Source

Added debug functionality

tree_alloc
Thomas Johnson 1 year ago
parent
commit
69f01b6544
  1. 10
      tree_alloc.c

10
tree_alloc.c

@ -7,14 +7,24 @@
#ifdef DEBUG
#include <stdio.h>
int debug_tree_black_height(TreeAlloc *node) {
if (node == NULL) {
return 1;
}
return ((node->color == COLOR_BLACK) ? 1 : 0) + debug_tree_black_height(node->left);
}
void debug_print_tree(int indent, void *p) {
TreeAlloc *node = (TreeAlloc*) p;
if (node != NULL) {
int bad = debug_tree_black_height(node->left) != debug_tree_black_height(node->right);
debug_print_tree(indent + 1, node->left);
for (int ii = 0; ii < indent; ii++) { printf(" "); }
if (node->color == COLOR_RED) { printf("\e[31m"); }
if (bad) { printf("\e[43m"); }
printf("%p %lu\n", node, node->size);
if (node->color == COLOR_RED) { printf("\e[37m"); }
if (bad) { printf("\e[40m"); }
debug_print_tree(indent + 1, node->right);
}
}

Loading…
Cancel
Save