GitHub - y-256/libdivsufsort: A lightweight suffix-sorting library (original) (raw)

libdivsufsort

libdivsufsort is a software library that implements a lightweight suffix array construction algorithm.

News

Introduction

This library provides a simple and an efficient C API to construct a suffix array and a Burrows-Wheeler transformed string from a given string over a constant-size alphabet. The algorithm runs in O(n log n) worst-case time using only 5n+O(1) bytes of memory space, where n is the length of the string.

Build requirements

Building on GNU/Linux

  1. Get the source code from GitHub. You can either
    • use git to clone the repository
git clone https://github.com/y-256/libdivsufsort.git  
  1. Create a build directory in the package source directory.

$ cd libdivsufsort $ mkdir build $ cd build

  1. Configure the package for your system. If you want to install to a different location, change the -DCMAKE_INSTALL_PREFIX option.

$ cmake -DCMAKE_BUILD_TYPE="Release"
-DCMAKE_INSTALL_PREFIX="/usr/local" ..

  1. Compile the package.
  2. (Optional) Install the library and header files.

API

/* Data types */ typedef int32_t saint_t; typedef int32_t saidx_t; typedef uint8_t sauchar_t;

/*

/*

Example Usage

#include <stdio.h> #include <stdlib.h> #include <string.h>

#include <divsufsort.h>

int main() { // intput data char *Text = "abracadabra"; int n = strlen(Text); int i, j;

// allocate
int *SA = (int *)malloc(n * sizeof(int));

// sort
divsufsort((unsigned char *)Text, SA, n);

// output
for(i = 0; i < n; ++i) {
    printf("SA[%2d] = %2d: ", i, SA[i]);
    for(j = SA[i]; j < n; ++j) {
        printf("%c", Text[j]);
    }
    printf("$\n");
}

// deallocate
free(SA);

return 0;

}

See the examples directory for a few other examples.

Benchmarks

See Benchmarks page for details.

License

libdivsufsort is released under the MIT license.

The MIT License (MIT)

Copyright (c) 2003 Yuta Mori All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author