Commit 00e56266 authored by jkvis's avatar jkvis

Added utility functions

parent b832e295
#include <stdlib.h>
#include "../include/gesa.h"
int GESA_calculate_lcp(GESA_char_t const* const string,
size_t const length,
GESA_index_t const* const sa,
GESA_index_t* const lcp)
{
GESA_index_t* const rank = malloc(length * sizeof(*rank));
if (rank == NULL)
{
return 1; // memory allocation failed
} // if
for (size_t i = 0; i < length; ++i)
{
rank[sa[i]] = i;
} // for
GESA_index_t h = 0;
for (size_t i = 0; i < length; ++i)
{
if (rank[i] > 0)
{
GESA_index_t const j = sa[rank[i] - 1];
while ((size_t) i + h < length &&
(size_t) j + h < length &&
string[i + h] == string[j + h])
{
h += 1;
} // while
lcp[rank[i]] = h;
if (h > 0)
{
h -= 1;
} // if
} // if
} // for
free(rank);
return 0;
} // GESA_calculate_lcp
int GESA_calculate_childtab(GESA const* const gesa,
GESA_index_t* const childtab)
{
static size_t const STACK_SIZE = 2048;
GESA_index_t stack[STACK_SIZE];
} // GESA_calculate_childtab
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment