static sg_error set_valid_filesystems(char const *fslist) { char const **newfs; char const **given_fs; while(sg_is_spc(*fslist)) ++fslist; if('!' == *fslist) { size_t new_items = 0, given_items = 0; const char **old_valid_fs = sg_get_valid_filesystems(0); if( NULL == old_valid_fs ) sg_die("sg_get_valid_filesystems()", 1); ++fslist; while(*fslist && sg_is_spc(*fslist)) ++fslist; given_fs = split_list(fslist); for(newfs = given_fs; *newfs; ++newfs) { ++given_items; } qsort(given_fs, given_items, sizeof(given_fs[0]), fsnmcmp); newfs = NULL; new_items = 0; while(*old_valid_fs) { if (NULL == bsearch(old_valid_fs, given_fs, given_items, sizeof(given_fs[0]), fsnmcmp)) { newfs = push_item(newfs, *old_valid_fs, new_items++); } ++old_valid_fs; } newfs = push_item(newfs, NULL, new_items); } else { newfs = given_fs = split_list(fslist); } if( SG_ERROR_NONE != sg_set_valid_filesystems( newfs ) ) sg_die("sg_set_valid_filesystems() failed", 1); for(newfs = given_fs; *newfs; ++newfs) { free((void *)(*newfs)); } return SG_ERROR_NONE; }
void test_list_ops(list* l) { printf("list ops tests\n"); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { assert(add(l, i, create_testdata("test_testdata", i)) == true); } } assert(size(l) == 10000); struct testdata* test_testdata = create_testdata("our_test", 20); add(l, 1024, test_testdata); assert(get(l, 1024) == test_testdata); assert(size(l) == 10001); assert(list_remove(l, 1024) == test_testdata); free_testdata(test_testdata); assert(size(l) == 10000); list* l2 = split_list(l, is_integer_val_50); assert(size(l2) == 100); assert(size(l) == 9900); traverse(l, _traverse_all_integer_val_ne_50); traverse(l2, _traverse_all_integer_val_eq_50); free_td_list(l2); }
void test_emptyList(list* l) { printf("empty list tests\n"); assert(is_empty(l)); assert(pop_front(l) == NULL); empty_list(l, free_testdata); empty_list(l, free_testdata); assert(is_empty(l)); assert(size(l) == 0); print_count = 0; last_printed = NULL; traverse(l, print_testdata); assert(print_count == 0); list* l2 = split_list(l, is_integer_val_23_or_greater); assert(is_empty(l)); assert(is_empty(l2)); list* l3 = copy_list(l, copy_testdata); assert(is_empty(l3)); assert(get(l, 0) == NULL); assert(front(l) == NULL); struct testdata* td = create_testdata("Alex", 0); assert(contains(l, td, testdata_string_val_comp) == NULL); free_testdata(td); free_td_list(l2); free_td_list(l3); }
int asm_parsing(header_t *header, char **stock, char *name) { int i; t_args *args; t_list *list; i = -1; if (!(args = my_calloc(1, sizeof(*args)))) return (FAILURE); if (!(list = init_list())) return (FAILURE); while (stock[++i]) { stock[i] = epur_str(stock[i]); if (split_list(stock[i], args) == FAILURE) return (FAILURE); if (line_parsing(args, list, name) == FAILURE) return (FAILURE); } double_free(stock); remplace_label(list); get_every_label_value(list); write_in_file(list, header, name); return (SUCCESS); }
long split_cell(const struct pqNode *p, long head) { int i; int lcount=0, rcount=0; int d; FLOAT fSplit; union split_u split; for (;;) { struct pqNode *left=NULL, *right=NULL; lcount = rcount = 0; assign_split(head, &d, &fSplit); #if 0 { split = head->cell.split; d = SPLIT_D(split); fSplit = SPLIT_FSPLIT(split); } #endif /**/ assert(d != 4); split_list(head, &left, &right, &lcount, &rcount); _DA_ fprintf(err, "Left count = %i Right count = %i\n", lcount, rcount); //_DA_ fprintf(err, "d=%i fSplit=%f\n", SPLIT_D(head->cell.split), head->cell.split.fSplit); NODE(head)->cell.list = NULL; NODE(head)->cell.count = 0; NODE(head)->cell.left_count = 0; create_left_branch(head, d); NODE(NODE(head)->pLeft)->cell.list = left; NODE(NODE(head)->pLeft)->cell.count = lcount; create_right_branch(head, d); NODE(NODE(head)->pRight)->cell.list = right; NODE(NODE(head)->pRight)->cell.count = rcount; comparisonCount++; if (p->r[d] < fSplit) { head = NODE(head)->pLeft; if (rcount != 0) break; } else { head = NODE(head)->pRight; if (lcount != 0) break; } } return head; }
t_list *merge_sort_matches(t_list *first) { t_list *second; if (!first || !first->next) return (first); second = split_list(first); first = merge_sort_matches(first); second = merge_sort_matches(second); return (merge_lists(first, second)); }
void merge_sort(struct node **head_ref){ if( (*head_ref)==NULL || (*head_ref)->next==NULL) return; struct node *temp = *head_ref; struct node *a; struct node *b; split_list(temp, &a, &b); merge_sort(&a); merge_sort(&b); *head_ref = merge(a, b); }
//Merge sort algo ll_ptr msort(ll_ptr nd,int *inv_ctr) { if(nd == NULL || nd->next ==NULL) { print_ll(nd); return nd; } ll_ptr ft = NULL; ll_ptr bk = NULL; split_list(nd,&ft,&bk); ll_ptr nd1 = msort(ft,inv_ctr); ll_ptr nd2 = msort(bk,inv_ctr); return smerge(nd1,nd2,inv_ctr); //ll_ptr nd_ret = NULL; //nd_ret = smerge_recur(&nd_ret,nd1,nd2); //return nd_ret; }
inline int split_cell(pTree *head) { int i; int d = head->d; FLOAT fSplit = head->fSplit; CREATE_BRANCH(pLeft, -); CREATE_BRANCH(pRight, +); /**/ assert(head->pLeft->cell.count == 0); /**/ assert(head->pRight->cell.count == 0); split_list(head); //_DA_ fprintf(err, "%e %e %e\n", head->cell.fMass, head->pLeft->cell.fMass, head->pRight->cell.fMass); //_DA_ fprintf(err, "%i %e\n", head->d, head->fSplit); _DA_ fprintf(err, "Left count = %i Right count = %i\n", head->pLeft->cell.count, head->pRight->cell.count); // /**/ assert(head->cell.fMass == (head->pLeft->cell.fMass + head->pRight->cell.fMass)); head->cell.list = NULL; head->cell.count = 0; return d; }