File: index_sufarray.cpp

package info (click to toggle)
seqan 1.4.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 34,164 kB
  • sloc: cpp: 226,267; python: 7,737; xml: 189; sh: 153; awk: 129; makefile: 48
file content (27 lines) | stat: -rw-r--r-- 650 bytes parent folder | download | duplicates (4)
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;
}