Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Is it possible to make reference to substrings and sort them?

by hdb (Monsignor)
on Mar 22, 2015 at 13:20 UTC ( [id://1120887]=note: print w/replies, xml ) Need Help??


in reply to Re: Is it possible to make reference to substrings and sort them?
in thread Is it possible to make reference to substrings and sort them?

If you can spare the memory to double your text, you can create references to all your rotations. Below I use the Schwartzian transform to create the references once, then sort them.

my $text2 = "$text$text"; my $bwt4 = join('', map{substr($text, ($_ - 1), 1)} map{ $_->[0] } sort{ ${$a->[1]} cmp ${$b->[1]} } map{ [$_,\substr($text2,$_,$ntext)] } 0..$ntext-1 ); print "$text: $bwt4\n";
  • Comment on Re^2: Is it possible to make reference to substrings and sort them?
  • Download Code

Replies are listed 'Best First'.
Re^3: Is it possible to make reference to substrings and sort them?
by Anonymous Monk on Mar 22, 2015 at 19:17 UTC

    Good call on doubling the string. Though the Schwartzian seems unnecessary here:

    my $text2 = "$text$text"; my $tlen = length($text); my $bwt7 = join('', map{ substr($$_, -1) } sort{ $$a cmp $$b } map{ \substr($text2, $_, $tlen) } 0..$tlen-1 ); print "$text: $bwt7\n";

    Intermediate array of references consumes more memory than an array of offsets would, I think, but is faster to sort. Something to test and benchmark...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1120887]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-25 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found