Skip to content

Commit

Permalink
Fixed an issue than output symbol frequency table is not calculated f…
Browse files Browse the repository at this point in the history
…or inputs of 0 or 1 bytes.
  • Loading branch information
IlyaGrebnov committed Mar 30, 2022
1 parent bca1eb2 commit 873f15d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 42 deletions.
40 changes: 23 additions & 17 deletions src/libsais.c
Original file line number Diff line number Diff line change
Expand Up @@ -6602,7 +6602,8 @@ int32_t libsais(const uint8_t * T, int32_t * SA, int32_t n, int32_t fs, int32_t
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { SA[0] = 0; if (freq != NULL) { freq[T[0]]++; } }
return 0;
}

Expand Down Expand Up @@ -6632,7 +6633,8 @@ int32_t libsais_ctx(const void * ctx, const uint8_t * T, int32_t * SA, int32_t n
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { SA[0] = 0; if (freq != NULL) { freq[T[0]]++; } }
return 0;
}

Expand All @@ -6647,8 +6649,9 @@ int32_t libsais_bwt(const uint8_t * T, uint8_t * U, int32_t * A, int32_t n, int3
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }
return n;
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
return n;
}

sa_sint_t index = libsais_main(T, A, n, 1, 0, NULL, fs, freq, 1);
Expand All @@ -6671,9 +6674,9 @@ int32_t libsais_bwt_aux(const uint8_t * T, uint8_t * U, int32_t * A, int32_t n,
return -1;
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }

{
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
I[0] = n;
return 0;
}
Expand All @@ -6697,9 +6700,10 @@ int32_t libsais_bwt_ctx(const void * ctx, const uint8_t * T, uint8_t * U, int32_
return -1;
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }
return n;
{
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
return n;
}

sa_sint_t index = libsais_main_ctx((const LIBSAIS_CONTEXT *)ctx, T, A, n, 1, 0, NULL, fs, freq);
Expand Down Expand Up @@ -6728,9 +6732,9 @@ int32_t libsais_bwt_aux_ctx(const void * ctx, const uint8_t * T, uint8_t * U, in
return -1;
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }

{
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
I[0] = n;
return 0;
}
Expand Down Expand Up @@ -6771,7 +6775,8 @@ int32_t libsais_omp(const uint8_t * T, int32_t * SA, int32_t n, int32_t fs, int3
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { SA[0] = 0; if (freq != NULL) { freq[T[0]]++; } }
return 0;
}

Expand Down Expand Up @@ -6805,7 +6810,8 @@ int32_t libsais_bwt_omp(const uint8_t * T, uint8_t * U, int32_t * A, int32_t n,
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
return n;
}

Expand All @@ -6832,8 +6838,8 @@ int32_t libsais_bwt_aux_omp(const uint8_t * T, uint8_t * U, int32_t * A, int32_t
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0];}

if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
I[0] = n;
return 0;
}
Expand Down
40 changes: 23 additions & 17 deletions src/libsais16.c
Original file line number Diff line number Diff line change
Expand Up @@ -6567,7 +6567,8 @@ int32_t libsais16(const uint16_t * T, int32_t * SA, int32_t n, int32_t fs, int32
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { SA[0] = 0; if (freq != NULL) { freq[T[0]]++; } }
return 0;
}

Expand All @@ -6582,7 +6583,8 @@ int32_t libsais16_ctx(const void * ctx, const uint16_t * T, int32_t * SA, int32_
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { SA[0] = 0; if (freq != NULL) { freq[T[0]]++; } }
return 0;
}

Expand All @@ -6596,8 +6598,9 @@ int32_t libsais16_bwt(const uint16_t * T, uint16_t * U, int32_t * A, int32_t n,
return -1;
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }
{
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
return n;
}

Expand All @@ -6621,9 +6624,9 @@ int32_t libsais16_bwt_aux(const uint16_t * T, uint16_t * U, int32_t * A, int32_t
return -1;
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }

{
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
I[0] = n;
return 0;
}
Expand All @@ -6647,9 +6650,10 @@ int32_t libsais16_bwt_ctx(const void * ctx, const uint16_t * T, uint16_t * U, in
return -1;
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }
return n;
{
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
return n;
}

sa_sint_t index = libsais16_main_ctx((const LIBSAIS_CONTEXT *)ctx, T, A, n, 1, 0, NULL, fs, freq);
Expand Down Expand Up @@ -6678,9 +6682,9 @@ int32_t libsais16_bwt_aux_ctx(const void * ctx, const uint16_t * T, uint16_t * U
return -1;
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }

{
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
I[0] = n;
return 0;
}
Expand Down Expand Up @@ -6721,7 +6725,8 @@ int32_t libsais16_omp(const uint16_t * T, int32_t * SA, int32_t n, int32_t fs, i
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { SA[0] = 0; if (freq != NULL) { freq[T[0]]++; } }
return 0;
}

Expand All @@ -6738,7 +6743,8 @@ int32_t libsais16_bwt_omp(const uint16_t * T, uint16_t * U, int32_t * A, int32_t
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
return n;
}

Expand All @@ -6765,8 +6771,8 @@ int32_t libsais16_bwt_aux_omp(const uint16_t * T, uint16_t * U, int32_t * A, int
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0];}

if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int32_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
I[0] = n;
return 0;
}
Expand Down
20 changes: 12 additions & 8 deletions src/libsais64.c
Original file line number Diff line number Diff line change
Expand Up @@ -6608,7 +6608,8 @@ int64_t libsais64(const uint8_t * T, int64_t * SA, int64_t n, int64_t fs, int64_
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int64_t)); }
if (n == 1) { SA[0] = 0; if (freq != NULL) { freq[T[0]]++; } }
return 0;
}

Expand Down Expand Up @@ -6637,7 +6638,8 @@ int64_t libsais64_bwt(const uint8_t * T, uint8_t * U, int64_t * A, int64_t n, in
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int64_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
return n;
}

Expand Down Expand Up @@ -6675,8 +6677,8 @@ int64_t libsais64_bwt_aux(const uint8_t * T, uint8_t * U, int64_t * A, int64_t n
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }

if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int64_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
I[0] = n;
return 0;
}
Expand Down Expand Up @@ -6717,7 +6719,8 @@ int64_t libsais64_omp(const uint8_t * T, int64_t * SA, int64_t n, int64_t fs, in
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int64_t)); }
if (n == 1) { SA[0] = 0; if (freq != NULL) { freq[T[0]]++; } }
return 0;
}

Expand Down Expand Up @@ -6748,7 +6751,8 @@ int64_t libsais64_bwt_omp(const uint8_t * T, uint8_t * U, int64_t * A, int64_t n
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0]; }
if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int64_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
return n;
}

Expand Down Expand Up @@ -6788,8 +6792,8 @@ int64_t libsais64_bwt_aux_omp(const uint8_t * T, uint8_t * U, int64_t * A, int64
}
else if (n <= 1)
{
if (n == 1) { U[0] = T[0];}

if (freq != NULL) { memset(freq, 0, ALPHABET_SIZE * sizeof(int64_t)); }
if (n == 1) { U[0] = T[0]; if (freq != NULL) { freq[T[0]]++; } }
I[0] = n;
return 0;
}
Expand Down

0 comments on commit 873f15d

Please sign in to comment.