| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
## no critic (prototypes) |
|
2
|
|
|
|
|
|
|
package SuffixTree; |
|
3
|
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
8918
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
71
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
82
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
require DynaLoader; |
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
10
|
use vars qw/$VERSION @ISA @EXPORT/; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
819
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = '0.07'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@ISA = qw(Exporter DynaLoader); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
bootstrap SuffixTree; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
@EXPORT = qw(ST_CreateTree ST_PrintTree ST_FindSubstring ST_DeleteTree |
|
19
|
|
|
|
|
|
|
create_tree print_tree find_substring delete_tree); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub create_tree($); |
|
22
|
|
|
|
|
|
|
sub print_tree($); |
|
23
|
|
|
|
|
|
|
sub find_substring($$); |
|
24
|
|
|
|
|
|
|
sub delete_tree($); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub create_tree($) { |
|
27
|
2
|
|
|
2
|
1
|
53
|
return ST_CreateTree($_[0], length($_[0])); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub print_tree($) { |
|
31
|
0
|
|
|
0
|
1
|
0
|
ST_PrintTree(shift); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub find_substring($$) { |
|
35
|
6
|
|
|
6
|
1
|
54
|
return ST_FindSubstring($_[0],$_[1],length($_[1])); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub delete_tree($) { |
|
39
|
2
|
|
|
2
|
1
|
111
|
ST_DeleteTree(shift); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
SuffixTree - Efficient string manipulation data structure interface for Perl. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
use SuffixTree; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $str = "mississippi"; |
|
51
|
|
|
|
|
|
|
my $tree=create_tree($str); |
|
52
|
|
|
|
|
|
|
print_tree($tree); |
|
53
|
|
|
|
|
|
|
my $position = find_substring($tree, "ssis"); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
printf("\nPosition of ssis in mississippi is %ld.\n\n", $position); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
delete_tree($tree); # NOTICE: this method will soon become deprecated |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 DEPRECATED SYNOPSIS |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use SuffixTree; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $str = "mississippi"; |
|
64
|
|
|
|
|
|
|
my $tree=ST_CreateTree($str, length($str)); |
|
65
|
|
|
|
|
|
|
ST_PrintTree($tree); |
|
66
|
|
|
|
|
|
|
my $position = ST_FindSubstring($tree, "ssis", 4); |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
printf("\nPosition of ssis in mississippi is %ld.\n\n", $position); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
ST_DeleteTree($tree); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
The intention of this project is to provide an open-source implementation |
|
76
|
|
|
|
|
|
|
for an efficient data structure for strings manipulation - the Suffix Tree. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The code was written with as much consistency with the theoretical algorithm |
|
79
|
|
|
|
|
|
|
as possible (see references). It provides a set of interface functions for |
|
80
|
|
|
|
|
|
|
creating and searching the tree. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The suffix tree is implemented in ANSI-C. The code is written based on the |
|
83
|
|
|
|
|
|
|
original algorithm by E.Ukkonen. This is the Perl interface for the underlying |
|
84
|
|
|
|
|
|
|
ANSI-C implementation. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
All functions are exported by default. Please note that all these interface |
|
89
|
|
|
|
|
|
|
functions were automatically extracted from the ANSI-C header file, so they |
|
90
|
|
|
|
|
|
|
might not behave as Perlish as you'd expect them to. This is something we |
|
91
|
|
|
|
|
|
|
will definitly address in the future. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item $tree = create_tree($string) |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Allocates memory for the tree and starts Ukkonen's construction algorithm. |
|
98
|
|
|
|
|
|
|
Parameters: A string. Returns a reference to the tree. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item $position = find_substring($tree, $substring) |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Searches for a string in the tree. It traverses the tree down starting |
|
103
|
|
|
|
|
|
|
its root like in a regular trie. Parameters: the tree to search in, a |
|
104
|
|
|
|
|
|
|
substring to look for. Returns the 1-based position it was found in the source |
|
105
|
|
|
|
|
|
|
string or 0 if string is not in the tree. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item print_tree($tree) |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Prints the tree. |
|
110
|
|
|
|
|
|
|
Parameters: the tree to print. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item delete_tree($tree) |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Deletes a suffix tree. |
|
115
|
|
|
|
|
|
|
Parameters: the tree to delete. |
|
116
|
|
|
|
|
|
|
Returns : void. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=back |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 DEPRECATED FUNCTIONS |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
All functions are exported by default. Please note that all these interface |
|
123
|
|
|
|
|
|
|
functions were automatically extracted from the ANSI-C header file, so they |
|
124
|
|
|
|
|
|
|
might not behave as Perlish as you'd expect them to. This is something we |
|
125
|
|
|
|
|
|
|
will try to address in the future. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over 4 |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item $tree = ST_CreateTree($string, length($string)) |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Allocates memory for the tree and starts Ukkonen's construction algorithm. |
|
132
|
|
|
|
|
|
|
Parameters: A string, length of the string. Returns a reference to the tree. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item $position = ST_FindSubstring($tree, $substring, length($substring)) |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Searches for a string in the tree. It traverses the tree down starting |
|
137
|
|
|
|
|
|
|
its root like in a regular trie. Parameters: the tree to search in, a |
|
138
|
|
|
|
|
|
|
substring to look for, length of substring. Returns the 1-based position it was |
|
139
|
|
|
|
|
|
|
found in the source string or 0 if string is not in the tree. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item ST_PrintTree($tree) |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Prints the tree. |
|
144
|
|
|
|
|
|
|
Parameters: the tree to print. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item ST_DeleteTree($tree) |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Deletes a suffix tree. |
|
149
|
|
|
|
|
|
|
Parameters: the tree to delete. |
|
150
|
|
|
|
|
|
|
Returns : void. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 BUGS |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This Perl interface was mostly built automatically (using SWIG). Little to no |
|
157
|
|
|
|
|
|
|
attention was given to testing. In future relases of this Perl Module (along with |
|
158
|
|
|
|
|
|
|
its underlying ANSI-C implementation) we hope to fix all problems that might |
|
159
|
|
|
|
|
|
|
currenly interfere with successful usage of this module. Please send bug reports |
|
160
|
|
|
|
|
|
|
to the current maintainer(s) of this module. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 FUTURE WORK |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
[1] A better Perl-ish interface |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
[2] Building tests for this module (for the `make test` part of the installation) |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
[3] Object Oriented like usage |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 PORTABILITY |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Please read the README file for information. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L - This module's Github |
|
177
|
|
|
|
|
|
|
repository. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L - Wikipedia's Suffix Tree |
|
180
|
|
|
|
|
|
|
explanation. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 AUTHOR |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Shlomo Yona Eyona@cs.technion.ac.ilE is the original author. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
David Oswald Edavido@cpan.orgE is the current maintainer. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 THANKS TO |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Offer Kaye for useful ideas and support. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Copyright (c) 2002, 2003, 2012 Shlomo Yona. All rights reserved. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
|
198
|
|
|
|
|
|
|
the terms of either: the GNU General Public License as published by the Free |
|
199
|
|
|
|
|
|
|
Software Foundation; or the Artistic License. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
See L for more information. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |