void second() { BitVector bv; bv.ptr = NULL; bv.size = 0; if (init_bit_vector(&bv, MAXSIZE)){ clear_allbits(&bv); // to do free_bit_vector(&bv); } }
void third(const char * const input_file, const char * const output_file) { assert(NULL != input_file && NULL != output_file); if (NULL == output_file || NULL == input_file) return; FILE *fp_in = fopen(input_file, "r"); FILE *fp_out = fopen(output_file, "w+"); if (NULL == fp_in || NULL == fp_out) return; BitVector bv; bv.ptr = NULL; bv.size = 0; if (!init_bit_vector(&bv, MAXSIZE)) return; clear_allbits(&bv); int cnt = 0; int tmp = 0; while (EOF != fscanf(fp_in, "%d\n", &tmp)){ set_bit(bv.ptr, tmp); cnt++; } fclose(fp_in); int i = 0; while (i < MAXSIZE) { if (get_bit(bv.ptr, i)){ fprintf(fp_out, "%d\n", i); if (0 == cnt--) break; } i++; } fclose(fp_out); free_bit_vector(&bv); }
void ui() { int choice, len = 0; char* input = malloc(sizeof(char)*MAX_INPUT_STRING_LENGTH); char* res = malloc(sizeof(char)); int* array = calloc(20, sizeof(int)); print_choices(); printf("Write the number of the operation you want to do:\n"); scanf("%d", &choice); printf("Give the input string: (max size %d) ", MAX_INPUT_STRING_LENGTH); print_instructions(choice); scanf("%s", input); wavelet_tree* root = create_wavelet_tree(input); wavelet_tree* res_root; if (choice == 1) { char** strings = malloc(sizeof(char*)); strings[0] = input; iterator_state* state = initialize_iterator(strings, 1); single_iterate(state, &print_node, 0); free_iterator_state(state); free(strings); } else if (choice == 2) { res_root = s_to_bwt(input); print_wavelet_tree(res_root); } else if (choice == 3) { res = bwt_to_s(root); printf("%s\n", res); } else if (choice == 4) { res_root = reverse_bwt(input); print_wavelet_tree(res_root); } else if (choice == 5) { array = create_c_array(root,0,0,0,0); int len = strlen(determine_alphabet(input)); print_int_array(array, len); } else if (choice == 6) { bit_vector* runs = create_runs_vector(root,0); print_runs_vector(runs, strlen(input)+1); free_bit_vector(runs); } else if (choice == 7) { printf("Give the second input string: "); char* input2 = malloc(sizeof(char)*MAX_INPUT_STRING_LENGTH); scanf("%s", input2); char** strings = malloc(2 * sizeof(char*)); strings[0] = input; strings[1] = input2; parameter_struct* params = initialize_for_mums(strings, 0); iterator_state* state = iterate(params); mum_results* results = (mum_results*) params->ret_data; triplet* nodes = results->data; print_mums(input, results, state); mum_print_bit_vectors(input,input2, results, state); free(strings); free(results->data); free_iterator_state(state); } else if (choice == 8) { printf("Not supported yet\n"); } else if (choice == 9) { printf("%d\n", distinct_substrings(input)); } else if (choice == 10) { parameter_struct* params = initialize_for_max_repeats(input, 0); iterator_state* state = iterate(params); max_repeat_results* results = (max_repeat_results*) params->ret_data; //maximals_print_nodes(input); print_maximal_repeat_substrings(input, results, state); //compare_quick_sort() } else if (choice == 11) { printf("Give the second input string: "); char* input2 = malloc(sizeof(char)*MAX_INPUT_STRING_LENGTH); scanf("%s", input2); char** strings = malloc(2 * sizeof(char*)); strings[0] = input; strings[1] = input2; parameter_struct* params = initialize_for_mems(strings, 0); iterator_state* state = iterate(params); mem_results* results = (mem_results*) params->ret_data; triplet* nodes = results->data; print_mems(input, results, state); free(strings); free(results->data); free_iterator_state(state); }else { printf("Invalid choice\n"); } }