in reply to Re: suffix array efficiency
in thread suffix array efficiency
Please include comparison(20000,1,10); in your bench.
Your caching strategy blows up in the degenerate case where $string eq "aaaa"...
I'd suggest something simpler:
Probably only works in C locale. Correctness unverified.sub xxx { my $string = shift; my @cache = unpack q(x*X3 .@0/(NX3)), $string."\0\0\0"; my @indices = sort {$cache[$a] <=> $cache[$b] || substr($string, $a) cmp substr($string, $b) } 0 .. $#cache; $_++ for @indices; return @indices; }
Update: Oops, copy-pasta fix.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: suffix array efficiency
by kennethk (Abbot) on Jan 20, 2014 at 19:09 UTC | |
|
Re^3: suffix array efficiency
by kennethk (Abbot) on Jan 20, 2014 at 19:23 UTC | |
by oiskuu (Hermit) on Jan 20, 2014 at 19:50 UTC | |
by kennethk (Abbot) on Jan 20, 2014 at 20:16 UTC |