in reply to suffix array efficiency
Instead of creating the suffixes, you can directly sort the indices based on a call to substr in sort. My machine does this in less than 2 minutes for a random string of length 200,000.
use strict; use warnings; sub suffix { my $string = shift; my @array = sort { substr( $string, $a ) cmp substr( $string, $b ) + } 0..length($string)-1; $_++ for @array; return @array; } my $n = 200000; my $input = join '', map { ('a'..'z')[rand(26)] } 0..$n-1; my @result = suffix $input; print "@result\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: suffix array efficiency
by RobertCraven (Sexton) on Jan 20, 2014 at 13:31 UTC |