liblash

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

tree2_shifttest.c (1367B)


      1 #include "../lash_tree2.h"
      2 #include "../lash_tree2_dump.h"
      3 #include <stdlib.h>
      4 #include <stdio.h>
      5 #include <limits.h>
      6 #include <time.h>
      7 
      8 #define TREE_CAPACITY 100
      9 #define HEAP_RANGE 1000
     10 
     11 int main(int argc, char **argv) {
     12 	time_t t;
     13 	lash_tree_t *tree;
     14 	int i;
     15 	int j;
     16 	char pushvaluestring[255];
     17 	char *local;
     18 	long int lastnumber;
     19 	
     20 	srand((unsigned) time(&t));
     21 	
     22 	tree = lash_treeInit(tree, TREE_CAPACITY);
     23 	if (tree == NULL)
     24 		return 1;
     25 		
     26 	lash_treeDumpInit(1);
     27 	lash_treeDumpAdd(tree, "tree");
     28 	
     29 	i = 0;
     30 	for (j = 0; j < TREE_CAPACITY; j++) {
     31 		long int pushvalue = -1;
     32 		if (j > 0)
     33 			pushvalue = rand() % HEAP_RANGE;
     34 			
     35 		if (i % 2 == 0 && i > 0) {
     36 			long int number;
     37 			unsigned int local;
     38 			fprintf(stderr, "Shifting!\n");
     39 			lash_treeShift(tree, &number, &local);
     40 			fprintf(stderr, "Shift yield n%li l%d\n", number, local);
     41 			j--;
     42 		}
     43 		
     44 		sprintf(pushvaluestring, "before push [%li]", pushvalue);
     45 		fprintf(stderr, "pushing %li\n", pushvalue);
     46 		//lash_treeDump(tree, pushvaluestring);
     47 		lash_treePush(tree, pushvalue, 0);
     48 		lash_treeDump(tree, "after push");
     49 		i++;
     50 	}
     51 	
     52 	printf("Unpacking\n");
     53 	
     54 	lastnumber = -1;
     55 	for (i = 0; i < TREE_CAPACITY; i++) {
     56 		long int number;
     57 		lash_treeShift(tree, &number, &local);
     58 		printf("%li ", number);
     59 		if (number < lastnumber)
     60 			printf("SORTERROR! ");
     61 		lastnumber = number;
     62 	}
     63 	printf("\n");
     64 	
     65 	return 0;
     66 }