/*--

This file is a part of libsais, a library for linear time suffix array,
longest common prefix array and burrows wheeler transform construction.

   Copyright (c) 2021-2022 Ilya Grebnov <ilya.grebnov@gmail.com>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

Please see the file 3rdparty/libsais-LICENSE for full copyright information.

--*/

#ifndef LIBSAIS_H
#define LIBSAIS_H 1

#include <stdint.h>

/**
 * Constructs the suffix array of a given string.
 * @param T [0..n-1] The input string.
 * @param SA [0..n-1+fs] The output array of suffixes.
 * @param n The length of the given string.
 * @param fs The extra space available at the end of SA array (0 should be
 * enough for most cases).
 * @param freq [0..255] The output symbol frequency table (can be NULL).
 * @return 0 if no error occurred, -1 or -2 otherwise.
 */
int32_t libsais(const uint8_t * T, int32_t * SA, int32_t n, int32_t fs, int32_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.
 */
int32_t libsais_int(int32_t * T, int32_t * SA, int32_t n, int32_t k, int32_t fs);

#if defined(_OPENMP)
/**
 * Constructs the suffix array of a given string in parallel using OpenMP.
 * @param T [0..n-1] The input string.
 * @param SA [0..n-1+fs] The output array of suffixes.
 * @param n The length of the given string.
 * @param fs The extra space available at the end of SA array (0 should be
 * enough for most cases).
 * @param freq [0..255] The output symbol frequency table (can be NULL).
 * @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.
 */
int32_t libsais_omp(const uint8_t * T, int32_t * SA, int32_t n, int32_t fs, int32_t * freq, int32_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.
 */
int32_t libsais_int_omp(int32_t * T, int32_t * SA, int32_t n, int32_t k, int32_t fs, int32_t threads);

#endif

#endif
