tree_dump.c (1657B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #include "tree.h" 5 #include "tree_dump.h" 6 7 unsigned int lash_tree_dump_monitor_capacity; 8 unsigned int lash_tree_dump_monitor_count; 9 10 void lash_treeDump(lash_tree_t *tree, char *comment) { 11 int i; 12 int j; 13 14 lash_tree_t *currenttree; 15 16 for (i = 0; i < lash_tree_dump_monitor_count; i++) { 17 currenttree = *(lash_tree_dump_monitor.tree + i); 18 if (tree != NULL) 19 if (tree != currenttree) 20 continue; 21 22 printf("'%s' size %d", *(lash_tree_dump_monitor.name + i), currenttree->count); 23 if (comment != NULL) 24 printf(" (%s)", comment); 25 printf(":\n"); 26 27 for (j = 0; j < currenttree->count; j++) { 28 printf("i:%2d v:%3li\n", j, (long int)**(currenttree->key + j)); 29 } 30 } 31 } 32 33 int lash_treeDumpInit(unsigned int count) { 34 35 lash_tree_dump_monitor.tree = (lash_tree_t**)malloc(sizeof(lash_tree_t*) * count); 36 if (lash_tree_dump_monitor.tree == NULL) 37 return 1; 38 39 lash_tree_dump_monitor.name = (char**)malloc(sizeof(char) * 128 * count); 40 if (lash_tree_dump_monitor.name == NULL) 41 return 1; 42 43 lash_tree_dump_monitor_capacity = count; 44 lash_tree_dump_monitor_count = 0; 45 46 return 0; 47 } 48 49 int lash_treeDumpAdd(lash_tree_t *tree, char *name) { 50 if (lash_tree_dump_monitor_count == lash_tree_dump_monitor_capacity) 51 return 1; 52 53 *(lash_tree_dump_monitor.tree + lash_tree_dump_monitor_count) = tree; 54 *(lash_tree_dump_monitor.name + lash_tree_dump_monitor_count) = name; 55 56 lash_tree_dump_monitor_count++; 57 58 return 0; 59 } 60 61 void lash_treeDumpFree() { 62 if (lash_tree_dump_monitor.tree != NULL) 63 free(lash_tree_dump_monitor.tree); 64 65 if (lash_tree_dump_monitor.name != NULL) 66 free(lash_tree_dump_monitor.name); 67 }