liblash

A bianry tree implementation used for game development from scratch
git clone git://holbrook.no/liblash.git
Log | Files | Refs | LICENSE

lash_tree_dump.c (1962B)


      1 #include "lash_tree_dump.h"
      2 #include "lash_tree.h"
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 struct lash_tree_dump_monitor {
      7 	lash_tree_t **tree;
      8 	char **name;
      9 } lash_tree_dump_monitor;
     10 
     11 unsigned int lash_tree_dump_monitor_capacity;
     12 unsigned int lash_tree_dump_monitor_count;
     13 
     14 void lash_treeDump(lash_tree_t *dumptree, char *comment) {
     15 	int i;
     16 	int j;
     17 	//long int lastn = 0;
     18 	int falsesort = 0;
     19 	long int nn;
     20 	long int nc;
     21 	long int ni;
     22 	lash_tree_t *currenttree;
     23 	
     24 	for (i = 0; i < lash_tree_dump_monitor_count; i++) {
     25 		currenttree = *(lash_tree_dump_monitor.tree + i);
     26 		if (dumptree != NULL)
     27 			if (dumptree != currenttree)
     28 				continue;
     29 			
     30 		printf("Tree '%s' is now size %d", *(lash_tree_dump_monitor.name + i), currenttree->position);
     31 		if (comment != NULL)
     32 			printf(" (%s)", comment);
     33 		printf(": ");
     34 		
     35 		for (j = 1; j <= currenttree->position; j++) {
     36 			int ti = *(currenttree->idx + j - 1);
     37 			nn = *(currenttree->heap + ti);
     38 			ni = *(currenttree->local + ti);
     39 			nc = *(currenttree->heap + *(currenttree->idx + (int)(j/ 2) - 1));
     40 			printf("i%u:s%u,h%li,i%li ", j, ti, nn, ni);
     41 			if (nn < nc && j > 1)
     42 				falsesort = 1;
     43 		}
     44 		if (falsesort == 1) {
     45 			printf("SORTERROR!\n");
     46 		}
     47 		printf("\n");	
     48 	}
     49 }
     50 
     51 int lash_treeDumpInit(unsigned int count) {
     52 	
     53 	lash_tree_dump_monitor.tree = (lash_tree_t*)malloc(sizeof(lash_tree_t*) * count);
     54 	if (lash_tree_dump_monitor.tree == NULL)
     55 		return -1;
     56 		
     57 	lash_tree_dump_monitor.name = (char*)malloc(sizeof(char) * 128 * count);
     58 	if (lash_tree_dump_monitor.name == NULL)
     59 		return -1;
     60 	
     61 	lash_tree_dump_monitor_capacity = count;
     62 	lash_tree_dump_monitor_count = 0;
     63 	
     64 	return 0;	
     65 }
     66 
     67 int lash_treeDumpAdd(lash_tree_t *tree, char *name) {
     68 	if (lash_tree_dump_monitor_count == lash_tree_dump_monitor_capacity)
     69 		return -1;
     70 		
     71 	*(lash_tree_dump_monitor.tree + lash_tree_dump_monitor_count) = tree;
     72 	*(lash_tree_dump_monitor.name + lash_tree_dump_monitor_count) = name;	
     73 	
     74 	lash_tree_dump_monitor_count++;
     75 	
     76 	return 0;
     77 }