Skip to content

Commit

Permalink
Implemented suffix array construction of a long integer array (libsai…
Browse files Browse the repository at this point in the history
…s64).
  • Loading branch information
IlyaGrebnov committed May 27, 2024
1 parent 2e5f9c2 commit d4f940b
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Changes in 2.8.2 (May 27, 2024)
- Implemented suffix array construction of a long integer array (libsais64).

Changes in 2.8.1 (April 5, 2024)
- Fixed out-of-bound memory access issue for large inputs (libsais64).

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)

project(libsais VERSION 2.8.1 LANGUAGES C DESCRIPTION "libsais is a library for linear time suffix array, longest common prefix array and burrows wheeler transform construction based on induced sorting algorithm.")
project(libsais VERSION 2.8.2 LANGUAGES C DESCRIPTION "libsais is a library for linear time suffix array, longest common prefix array and burrows wheeler transform construction based on induced sorting algorithm.")

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ The libsais provides simple C99 API to construct suffix array and Burrows-Wheele
The libsais is released under the [Apache License Version 2.0](LICENSE "Apache license")

## Changes
* May 27, 2024 (2.8.2)
* Implemented suffix array construction of a long integer array (libsais64).
* April 5, 2024 (2.8.1)
* Fixed out-of-bound memory access issue for large inputs (libsais64).
* March 3, 2024 (2.8.0)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.1
2.8.2
4 changes: 2 additions & 2 deletions include/libsais.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Please see the file LICENSE for full copyright information.

#define LIBSAIS_VERSION_MAJOR 2
#define LIBSAIS_VERSION_MINOR 8
#define LIBSAIS_VERSION_PATCH 1
#define LIBSAIS_VERSION_STRING "2.8.1"
#define LIBSAIS_VERSION_PATCH 2
#define LIBSAIS_VERSION_STRING "2.8.2"

#ifdef _WIN32
#ifdef LIBSAIS_SHARED
Expand Down
4 changes: 2 additions & 2 deletions include/libsais16.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Please see the file LICENSE for full copyright information.

#define LIBSAIS16_VERSION_MAJOR 2
#define LIBSAIS16_VERSION_MINOR 8
#define LIBSAIS16_VERSION_PATCH 1
#define LIBSAIS16_VERSION_STRING "2.8.1"
#define LIBSAIS16_VERSION_PATCH 2
#define LIBSAIS16_VERSION_STRING "2.8.2"

#ifdef _WIN32
#ifdef LIBSAIS_SHARED
Expand Down
29 changes: 27 additions & 2 deletions include/libsais64.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Please see the file LICENSE for full copyright information.

#define LIBSAIS64_VERSION_MAJOR 2
#define LIBSAIS64_VERSION_MINOR 8
#define LIBSAIS64_VERSION_PATCH 1
#define LIBSAIS64_VERSION_STRING "2.8.1"
#define LIBSAIS64_VERSION_PATCH 2
#define LIBSAIS64_VERSION_STRING "2.8.2"

#ifdef _WIN32
#ifdef LIBSAIS_SHARED
Expand Down Expand Up @@ -60,6 +60,18 @@ extern "C" {
*/
LIBSAIS64_API int64_t libsais64(const uint8_t * T, int64_t * SA, int64_t n, int64_t fs, int64_t * freq);

/**
* Constructs the suffix array of a given integer array.
* Note, during construction input array will be modified, but restored at the end if no errors occurred.
* @param T [0..n-1] The input integer array.
* @param SA [0..n-1+fs] The output array of suffixes.
* @param n The length of the integer array.
* @param k The alphabet size of the input integer array.
* @param fs Extra space available at the end of SA array (can be 0, but 4k or better 6k is recommended for optimal performance).
* @return 0 if no error occurred, -1 or -2 otherwise.
*/
LIBSAIS64_API int64_t libsais64_long(int64_t * T, int64_t * SA, int64_t n, int64_t k, int64_t fs);

#if defined(LIBSAIS_OPENMP)
/**
* Constructs the suffix array of a given string in parallel using OpenMP.
Expand All @@ -72,6 +84,19 @@ extern "C" {
* @return 0 if no error occurred, -1 or -2 otherwise.
*/
LIBSAIS64_API int64_t libsais64_omp(const uint8_t * T, int64_t * SA, int64_t n, int64_t fs, int64_t * freq, int64_t threads);

/**
* Constructs the suffix array of a given integer array in parallel using OpenMP.
* Note, during construction input array will be modified, but restored at the end if no errors occurred.
* @param T [0..n-1] The input integer array.
* @param SA [0..n-1+fs] The output array of suffixes.
* @param n The length of the integer array.
* @param k The alphabet size of the input integer array.
* @param fs Extra space available at the end of SA array (can be 0, but 4k or better 6k is recommended for optimal performance).
* @param threads The number of OpenMP threads to use (can be 0 for OpenMP default).
* @return 0 if no error occurred, -1 or -2 otherwise.
*/
LIBSAIS64_API int64_t libsais64_long_omp(int64_t * T, int64_t * SA, int64_t n, int64_t k, int64_t fs, int64_t threads);
#endif

/**
Expand Down
2 changes: 1 addition & 1 deletion src/libsais.c
Original file line number Diff line number Diff line change
Expand Up @@ -6528,7 +6528,7 @@ static sa_sint_t libsais_main(const uint8_t * T, sa_sint_t * SA, sa_sint_t n, sa
return index;
}

static int32_t libsais_main_int(sa_sint_t * T, sa_sint_t * SA, sa_sint_t n, sa_sint_t k, sa_sint_t fs, sa_sint_t threads)
static sa_sint_t libsais_main_int(sa_sint_t * T, sa_sint_t * SA, sa_sint_t n, sa_sint_t k, sa_sint_t fs, sa_sint_t threads)
{
LIBSAIS_THREAD_STATE * RESTRICT thread_state = threads > 1 ? libsais_alloc_thread_state(threads) : NULL;

Expand Down
45 changes: 45 additions & 0 deletions src/libsais64.c
Original file line number Diff line number Diff line change
Expand Up @@ -6584,6 +6584,19 @@ static sa_sint_t libsais64_main(const uint8_t * T, sa_sint_t * SA, sa_sint_t n,
return index;
}

static sa_sint_t libsais64_main_long(sa_sint_t * T, sa_sint_t * SA, sa_sint_t n, sa_sint_t k, sa_sint_t fs, sa_sint_t threads)
{
LIBSAIS_THREAD_STATE * RESTRICT thread_state = threads > 1 ? libsais64_alloc_thread_state(threads) : NULL;

sa_sint_t index = thread_state != NULL || threads == 1
? libsais64_main_32s_entry(T, SA, n, k, fs, threads, thread_state)
: -2;

libsais64_free_thread_state(thread_state);

return index;
}

static void libsais64_bwt_copy_8u(uint8_t * RESTRICT U, sa_sint_t * RESTRICT A, sa_sint_t n)
{
const fast_sint_t prefetch_distance = 32;
Expand Down Expand Up @@ -6666,6 +6679,21 @@ int64_t libsais64(const uint8_t * T, int64_t * SA, int64_t n, int64_t fs, int64_
return libsais64_main(T, SA, n, 0, 0, NULL, fs, freq, 1);
}

int64_t libsais64_long(int64_t * T, int64_t * SA, int64_t n, int64_t k, int64_t fs)
{
if ((T == NULL) || (SA == NULL) || (n < 0) || (fs < 0))
{
return -1;
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
return 0;
}

return libsais64_main_long(T, SA, n, k, fs, 1);
}

int64_t libsais64_bwt(const uint8_t * T, uint8_t * U, int64_t * A, int64_t n, int64_t fs, int64_t * freq)
{
if ((T == NULL) || (U == NULL) || (A == NULL) || (n < 0) || (fs < 0))
Expand Down Expand Up @@ -6779,6 +6807,23 @@ int64_t libsais64_omp(const uint8_t * T, int64_t * SA, int64_t n, int64_t fs, in
return libsais64_main(T, SA, n, 0, 0, NULL, fs, freq, threads);
}

int64_t libsais64_long_omp(int64_t * T, int64_t * SA, int64_t n, int64_t k, int64_t fs, int64_t threads)
{
if ((T == NULL) || (SA == NULL) || (n < 0) || (fs < 0) || (threads < 0))
{
return -1;
}
else if (n < 2)
{
if (n == 1) { SA[0] = 0; }
return 0;
}

threads = threads > 0 ? threads : omp_get_max_threads();

return libsais64_main_long(T, SA, n, k, fs, threads);
}

int64_t libsais64_bwt_omp(const uint8_t * T, uint8_t * U, int64_t * A, int64_t n, int64_t fs, int64_t * freq, int64_t threads)
{
if ((T == NULL) || (U == NULL) || (A == NULL) || (n < 0) || (fs < 0) || (threads < 0))
Expand Down

0 comments on commit d4f940b

Please sign in to comment.