<tb@panthema.net>
<http://www.gnu.org/licenses/>
namespace lcp {
template <typename alphabet_type, typename offset_type>
void lcparray(const alphabet_type* string, const offset_type* SA, std::vector<offset_type>& lcp, unsigned int N)
{
std::vector<offset_type> ISA (N);
for(unsigned int i = 0; i < N; i++)
ISA[SA[i]] = i;
lcp.resize(N);
unsigned int h = 0;
lcp[0] = 0;
for(unsigned int i = 0; i < N; i++)
{
unsigned int k = ISA[i];
if (k > 0) {
unsigned int j = SA[k-1];
while(i + h < N && j + h < N &&
string[i+h] == string[j+h])
h++;
lcp[k] = h;
}
if (h > 0) h--;
}
}
template <typename alphabet_type, typename offset_type>
void lcparray(const std::vector<alphabet_type>& string, const std::vector<offset_type>& SA, std::vector<offset_type>& lcp)
{
assert(string.size() == SA.size());
lcparray(string.data(), SA.data(), lcp, string.size());
}
template <typename StringContainer, typename SAContainer, typename LCPContainer>
void lcparray_naive(const StringContainer& string, const SAContainer& SA, LCPContainer& lcp)
{
assert( string.size() == SA.size() );
lcp.resize(string.size());
lcp[0] = 0;
for (size_t i = 1; i < string.size(); ++i)
{
typename StringContainer::const_iterator
pa = string.begin() + SA[i-1],
pb = string.begin() + SA[i];
size_t h = 0;
while (pa != string.end() && pb != string.end() && *pa == *pb)
++pa, ++pb, ++h;
lcp[i] = h;
}
}
}