int32_t divsufsort(const uint8_t *T, int32_t *SA, int32_t n) { int32_t m; int32_t err = 0; /* Check arguments. */ if ((T == NULL) || (SA == NULL) || (n < 0)) { return -1; } else if (n == 0) { return 0; } else if (n == 1) { SA[0] = 0; return 0; } else if (n == 2) { m = (T[0] < T[1]); SA[m ^ 1] = 0, SA[m] = 1; return 0; } int32_t bucket_A [BUCKET_A_SIZE]; int32_t bucket_B [BUCKET_B_SIZE]; /* Suffixsort. */ m = sort_typeBstar(T, SA, bucket_A, bucket_B, n); construct_SA(T, SA, bucket_A, bucket_B, n, m); return err; }
saint_t divsufsort(const sauchar_t *T, saidx_t *SA, saidx_t n) { saidx_t *bucket_A, *bucket_B; saidx_t m; saint_t err = 0; /* Check arguments. */ if((T == NULL) || (SA == NULL) || (n < 0)) { return -1; } else if(n == 0) { return 0; } else if(n == 1) { SA[0] = 0; return 0; } else if(n == 2) { m = (T[0] < T[1]); SA[m ^ 1] = 0, SA[m] = 1; return 0; } // bucket_A = (saidx_t *)malloc(BUCKET_A_SIZE * sizeof(saidx_t)); // bucket_B = (saidx_t *)malloc(BUCKET_B_SIZE * sizeof(saidx_t)); bucket_A = bucketA_buffer; bucket_B = bucketB_buffer; /* Suffixsort. */ if((bucket_A != NULL) && (bucket_B != NULL)) { m = sort_typeBstar(T, SA, bucket_A, bucket_B, n); construct_SA(T, SA, bucket_A, bucket_B, n, m); } else { err = -2; } //free(bucket_B); //free(bucket_A); return err; }
saidx_t divbwt(const sauchar_t *T, sauchar_t *U, saidx_t *A, saidx_t n) { saidx_t *B; saidx_t *bucket_A, *bucket_B; saidx_t m, pidx, i; /* Check arguments. */ if((T == NULL) || (U == NULL) || (n < 0)) { return -1; } else if(n <= 1) { if(n == 1) { U[0] = T[0]; } return n; } if((B = A) == NULL) { B = (saidx_t *)malloc((size_t)(n + 1) * sizeof(saidx_t)); } bucket_A = (saidx_t *)malloc(BUCKET_A_SIZE * sizeof(saidx_t)); bucket_B = (saidx_t *)malloc(BUCKET_B_SIZE * sizeof(saidx_t)); /* Burrows-Wheeler Transform. */ if((B != NULL) && (bucket_A != NULL) && (bucket_B != NULL)) { m = sort_typeBstar(T, B, bucket_A, bucket_B, n); pidx = construct_BWT(T, B, bucket_A, bucket_B, n, m); /* Copy to output string. */ U[0] = T[n - 1]; for(i = 0; i < pidx; ++i) { U[i + 1] = (sauchar_t)B[i]; } for(i += 1; i < n; ++i) { U[i] = (sauchar_t)B[i]; } pidx += 1; } else { pidx = -2; } free(bucket_B); free(bucket_A); if(A == NULL) { free(B); } return pidx; }
saidx_t divbwtf(const sauchar_t *T, sauchar_t *U, saidx_t *A, saidx_t n, unsigned *LFpowers, unsigned nLFpowers, unsigned freqs[256]) { saidx_t *B; saidx_t *bucket_A, *bucket_B; saidx_t m, pidx, i; /* Check arguments. */ if((T == NULL) || (U == NULL) || (n < 0)) { return -1; } else if(n <= 1) { if(n == 1) { U[0] = T[0]; } return n; } if((B = A) == NULL) { B = (saidx_t *)malloc((size_t)(n + 1) * sizeof(saidx_t)); } bucket_A = (saidx_t *)malloc(BUCKET_A_SIZE * sizeof(saidx_t)); bucket_B = (saidx_t *)malloc(BUCKET_B_SIZE * sizeof(saidx_t)); /* Burrows-Wheeler Transform. */ if((B != NULL) && (bucket_A != NULL) && (bucket_B != NULL)) { m = sort_typeBstar(T, B, bucket_A, bucket_B, n); if(nLFpowers > 1) { pidx = construct_BWT(T, B, bucket_A, bucket_B, n, m, LFpowers, nLFpowers); LFpowers[0] = pidx; } else { pidx = construct_BWT_orig(T, B, bucket_A, bucket_B, n, m); *LFpowers = pidx; } /* Copy to output string. */ for(i = 0; i < n; ++i) { if(i != pidx) { U[i] = (sauchar_t)B[i]; ++freqs[U[i]]; } } } else { pidx = -2; } free(bucket_B); free(bucket_A); if(A == NULL) { free(B); } return pidx; }
int32_t divbwt(const uint8_t *T, uint8_t *U, int32_t *A, int32_t n) { int32_t *B; int32_t m, pidx, i; /* Check arguments. */ if ((T == NULL) || (U == NULL) || (n < 0)) { return -1; } else if (n <= 1) { if (n == 1) { U[0] = T[0]; } return n; } if ((B = A) == NULL) { B = new int32_t [ (n + 1)]; } int32_t bucket_A [BUCKET_A_SIZE]; int32_t bucket_B [BUCKET_B_SIZE]; /* Burrows-Wheeler Transform. */ m = sort_typeBstar(T, B, bucket_A, bucket_B, n); pidx = construct_BWT(T, B, bucket_A, bucket_B, n, m); /* Copy to output string. */ U[0] = T[n - 1]; for (i = 0; i < pidx; ++i) { U[i + 1] = (uint8_t) B[i]; } for (i += 1; i < n; ++i) { U[i] = (uint8_t) B[i]; } pidx += 1; if (A == NULL) delete[] B; return pidx; }