1 #include "sav.h" 2 #include "sort.h" 3 4 void sort_reset_stats(SAV *sav) { 5 if(sav == NULL) return; 6 7 sav->sel = sav->cmp = ARR_MAX + 1; 8 sav->cmps = sav->swps = sav->B_used = 0; 9 } 10 11 status_t SAV_create(SAV **sav) { 12 status_t st; 13 14 if((*sav = (SAV *)malloc(sizeof(SAV))) == NULL) 15 return ERROR_MEMORY_ALLOC; 16 17 (*sav)->sel = (*sav)->cmp = ARR_MAX + 1; 18 (*sav)->cmps = (*sav)->swps = (*sav)->its = (*sav)->B_used = 0; 19 20 /* defaults */ 21 (*sav)->status = WELCOME; 22 (*sav)->sort_status = PAUSE; 23 (*sav)->sort_algo = INSERTION_SORT; 24 (*sav)->sort_delay = SAV_DEFAULT_SORT_DELAY; 25 26 if((st = Arr_create(&(*sav)->arr)) != OK) 27 return st; 28 29 (*sav)->arr->shuffle_sel = RANDOM; 30 31 return OK; 32 } 33 34 void SAV_destroy(SAV *sav) { 35 if(sav == NULL) return; 36 37 Arr_destroy(sav->arr); 38 free(sav); 39 } 40 41 void sort_selector(SAV *sav) { 42 if(sav->sort_algo == (ALGORITHMS_COUNT - 1)) 43 sav->sort_algo = 0; 44 else sav->sort_algo++; 45 }