From 00e56266adf4a7cade2e3cbd84c2f45057a87c59 Mon Sep 17 00:00:00 2001 From: jkvis Date: Thu, 11 Jan 2018 10:05:12 +0100 Subject: [PATCH] Added utility functions --- src/utils.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/utils.c diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..5e09309 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,54 @@ +#include + +#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 -- GitLab