}END_TEST START_TEST (reverse_bwt_test2) { wavelet_tree* rbwt = reverse_bwt("HATTIVATTI"); ck_assert_int_eq(1, wavelet_tree_matches_string(rbwt,"HTTAV$TTIIA",11)); }END_TEST
}END_TEST START_TEST (reverse_bwt_test) { wavelet_tree* rbwt = reverse_bwt("ABRACADABRA"); ck_assert_int_eq(1, wavelet_tree_matches_string(rbwt,"ABDBC$RRAAAA",12)); }END_TEST
iterator_state* initialize_iterator(char** strings, unsigned int num_strings) { iterator_state* state = malloc(sizeof(iterator_state)); state->num_strings = num_strings; state->bwts = malloc(num_strings * sizeof(wavelet_tree)); state->reverse_bwts = malloc(num_strings * sizeof(wavelet_tree)); state->runs_vectors = malloc(num_strings * sizeof(bit_vector)); state->reverse_runs_vectors = malloc(num_strings * sizeof(bit_vector)); state->stacks = malloc(num_strings * sizeof(substring_stack)); state->alpha_datas = malloc(num_strings * sizeof(alphabet_data)); state->normals = malloc(num_strings * sizeof(interval)); state->reverses = malloc(num_strings * sizeof(interval)); state->current = malloc(num_strings * sizeof(substring)); state->prev = malloc(num_strings * sizeof(substring)); state->c_arrays = malloc(num_strings * sizeof(unsigned int*)); unsigned int common_alpha_length = 1; wavelet_tree* tree; bit_vector* vector; substring_stack* stack; for (int i = 0; i < num_strings; ++i) { state->alpha_datas[i].alphabet = 0; tree = s_to_bwt(strings[i]); memcpy(&state->bwts[i], tree, sizeof(wavelet_tree)); free(tree); tree = reverse_bwt(strings[i]); memcpy(&state->reverse_bwts[i], tree, sizeof(wavelet_tree)); free(tree); vector = create_runs_vector(&state->bwts[i], 0); memcpy(&state->runs_vectors[i], vector, sizeof(bit_vector)); free(vector); vector = create_runs_vector(&state->reverse_bwts[i], 0); memcpy(&state->reverse_runs_vectors[i], vector, sizeof(bit_vector)); free(vector); stack = create_stack(10); memcpy(&state->stacks[i], stack, sizeof(substring_stack)); free(stack); state->c_arrays[i] = malloc((state->bwts->get_alphabet_length(&state->bwts[i]) + 1) * sizeof(unsigned int)); common_alpha_length += state->bwts->get_alphabet_length(&state->bwts[i]); } if (num_strings > 1) { state->common_alphabet = malloc(sizeof(alphabet_data)); state->common_alphabet->alphabet = malloc(common_alpha_length * sizeof(char)); } else state->common_alphabet = 0; /*printf("State initialized:\n"); printf("\tNum strings: %u\n", state->num_strings); printf("\tBwts:"); for (int i = 0; i < num_strings; ++i) { printf(" "); for (int j = 0; j < state->bwts[i].get_num_bits(&state->bwts[i]); ++j) printf("%c", state->bwts[i].char_at(&state->bwts[i], j)); } printf("\n\tReverse bwts:"); for (int i = 0; i < num_strings; ++i) { printf(" "); for (int j = 0; j < state->reverse_bwts[i].get_num_bits(&state->reverse_bwts[i]); ++j) printf("%c", state->reverse_bwts[i].char_at(&state->reverse_bwts[i], j)); } printf("\n\tRuns vectors:\n"); for (int i = 0; i < num_strings; ++i) print_bit_vector(&state->runs_vectors[i]);*/ return state; }
int main(int argc, char** argv) { bit_file_t* f; FILE* outf; char* infile,*outfile; uint8_t* input,*bwt,*output,lumode; int32_t I,n; mode_t lupdate_alg; /* parse command line parameter */ if (argc !=2) { print_usage(argv[0]); exit(EXIT_FAILURE); } infile = argv[1]; /* read input file */ f = BitFileOpen(infile, BF_READ); if (!f) { fatal("could not open file %s.",infile); } /* check if compressed with aazip */ if (BitFileGetChar(f) != 'A' || BitFileGetChar(f) != 'A') { fatal("file %s not compressed with aazip.",infile); } fprintf(stdout,"FILE: %s\n",infile); /* read header */ BitFileGetBitsInt(f,&I,32,sizeof(I)); BitFileGetBitsInt(f,&lumode,8,sizeof(lumode)); lupdate_alg = lumode; input = decode_huffman(f,&n); /* malloc output memory */ bwt = safe_malloc(n*sizeof(uint8_t)); /* peform list update */ switch (lupdate_alg) { case SIMPLE: fprintf(stdout,"LUPDATE: Simple\n"); bwt = lupdate_simple(input,n,bwt); break; case MTF: fprintf(stdout,"LUPDATE: Move-To-Front\n"); bwt = lupdate_movetofront(input,n,bwt); break; case FC: fprintf(stdout,"LUPDATE: FC\n"); bwt = lupdate_freqcount(input,n,bwt); break; case WFC: fprintf(stdout,"LUPDATE: WFC\n"); bwt = lupdate_wfc(input,n,bwt); break; case TS: fprintf(stdout,"LUPDATE: TS\n"); bwt = lupdate_timestamp(input,n,bwt); break; default: fatal("unkown list update algorithm."); } /* reverse bwt */ output = reverse_bwt(bwt,n,I,input); /* write output */ outfile = safe_strcat(infile,".org"); outf = safe_fopen(outfile,"w"); if (fwrite(output,sizeof(uint8_t),n,outf)!= (size_t)n) { fatal("error writing output."); } safe_fclose(outf); /* clean up */ free(bwt); free(input); BitFileClose(f); return (EXIT_SUCCESS); }
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"); } }