tree_shifttest.c (1229B)
1 #include "../lash_tree.h" 2 #include "../lash_tree_dump.h" 3 #include <stdlib.h> 4 #include <stdio.h> 5 #include <limits.h> 6 #include <time.h> 7 8 #define TREE_CAPACITY 10 9 #define HEAP_RANGE 100 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 18 srand((unsigned) time(&t)); 19 20 tree = lash_treeInit(tree, TREE_CAPACITY); 21 if (tree == NULL) 22 return 1; 23 24 lash_treeDumpInit(1); 25 lash_treeDumpAdd(tree, "tree"); 26 27 i = 0; 28 for (j = 0; j < TREE_CAPACITY; j++) { 29 long int pushvalue = -1; 30 if (j > 0) 31 pushvalue = rand() % HEAP_RANGE; 32 33 if (i % 2 == 0 && i > 0) { 34 long int number; 35 unsigned int local; 36 fprintf(stderr, "Shifting!\n"); 37 lash_treeShift(tree, &number, &local); 38 fprintf(stderr, "Shift yield n%li l%d\n", number, local); 39 j--; 40 } 41 42 sprintf(pushvaluestring, "before push [%li]", pushvalue); 43 fprintf(stderr, "pushing %li\n", pushvalue); 44 //lash_treeDump(tree, pushvaluestring); 45 lash_treePush(tree, pushvalue, 0); 46 lash_treeDump(tree, "after push"); 47 i++; 48 } 49 50 printf("Unpacking\n"); 51 for (i = 0; i < TREE_CAPACITY; i++) { 52 long int number; 53 lash_treeShift(tree, &number, NULL); 54 printf("%li ", number); 55 } 56 printf("\n"); 57 58 return 0; 59 }