Piers Cawley wrote:
> 
> >"David L. Nicol" <[EMAIL PROTECTED]> writes:
> > After reading Cawley's
> > method, I wondered if using it we could make radix-sorts the
> > default sort method.
> 
> Er... the point behind changing numbers to binary strings was
> emphatically not so that they could be sorted by a Radix method, but
> to ensure that numbers within text would sort correctly: qw(A1 A2 A3
> A10) instead of qw(A1 A10 A2 A3)...

The rsort documentation informs that radix-sorts will sort ascii
text.

My thought was that the perl6 default sort could do an implied ST on
the data, using Cawley's Substitution, and then a radix-sort, instead
of analyzing each pair of data to see if they are numeric or not using
whatever the current heuristic is.

I do not know exactly what the perl5 default sort heuristic is, aside that
it tries to DWIM both numeric and string data.

Without the ST, the sort function would be

 sub PCsort {
   my $mya = $a;
   my $myb = $b;
     $mya =~ s/(\d+)/unpack("B32", pack("N",$1))/eg;
     $myb =~ s/(\d+)/unpack("B32", pack("N",$1))/eg;
  return $mya cmp $myb;
 }

With ST (and duplicate loss correction!)

   sub PCsort(@){
        my $this;
        my $trans;
        my %duplicates;
        my %doppleganger;
        while ($trans = $this = shift){
                $trans =~ s/(\d+)/unpack("B32", pack("N",$1))/eg;
                exists $doppleganger{$trans} and $duplicates{$trans}++;
                $doppleganger{$trans} = $this;
        };
        my @Sorted = sort {$a cmp $b} keys %doppleganger;
        my @result;     # from here down could be a map{} but it would be
                        # hard to understand....
        foreach $trans (@Sorted){
                do{
                        push @result, $doppleganger{$trans};
                }while($duplicates{$trans}--);
        };
        @result
   };




On another note, anyone for suppressing the use-of-unititalized warning
on the unary incrementors?


-- 
                           David Nicol 816.235.1187 [EMAIL PROTECTED]
                                Today in art class, draw your sword

Reply via email to