Suffix tree: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: fix markup)
m (→‎{{header|Perl 6}}: stabilize output, work-around for JVM bug)
Line 557: Line 557:


=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{Works with|Rakudo|2018.03}}
{{Works with|Rakudo|2018.04}}
Here is quite a naive algorithm, probably <math>O(n^2)</math>.
Here is quite a naive algorithm, probably <math>O(n^2)</math>.


Line 588: Line 588:
) {
) {
sub visit($node, *@pre) {
sub visit($node, *@pre) {
| gather {
gather {
take @pre[0] ~ $node.&label;
take @pre[0] ~ $node.&label;
my @children := $node.&children;
my @children = sort $node.&children;
my $end = @children.end;
my $end = @children.end;
for @children.kv -> $_, $child {
for @children.kv -> $_, $child {
Line 598: Line 598:
}
}
}
}
visit($tree, $indent xx 2);
flat visit($tree, $indent xx 2);
}</lang>
}</lang>