1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
///A tutorial about suffix arrays.
#include <iostream>
#include <seqan/index.h>
using namespace seqan;
int main ()
{
String<char> text = "hello world!";
String<char> pattern = "l";
String<unsigned> sa;
///Build a suffix array using the Skew7 algorithm.
resize(sa, length(text));
createSuffixArray(sa, text, Skew7());
///Search the interval of suffices beginning with the pattern.
Pair<unsigned> hitRange;
hitRange = equalRangeSA(text, sa, pattern);
///Output the suffix indices, i.e. the occurrences of the pattern.
for(unsigned i = hitRange.i1; i < hitRange.i2; ++i)
std::cout << sa[i] << " ";
std::cout << std::endl;
return 0;
}
|