[Tokyo.pm] JUS感想

Kazumasa Utashiro utashiro @ iij.ad.jp
1999年 10月 6日 (水) 06:25:30 CDT



From: IMAZU Hideyo <himazu @ ms.com>
Subject: [Tokyo.pm]  Re: [Tokyo.pm] JUS感想
Date: Wed, 06 Oct 1999 18:47:23 +0900

> シュワルツ変換のキモは比較のための計算量を最低限にするといいうこと
> ですから、

というのは違うと思いますよ。僕が指摘するまでもなく、すでに perlfaq4 に

       If you have a complicated function needed to pull out the
       part you want to sort on, then don't do it inside the sort
       function.  Pull it out first, because the sort BLOCK can
       be called many times for the same element.  Here's an
       example of how to pull out the first word after the first
       number on each item, and then sort those words case-

           @idx = ();
           for (@data) {
               ($item) = /\d+\s*(\S+)/;
               push @idx, uc($item);
           @sorted = @data[ sort { $idx[$a] cmp $idx[$b] } 0 .. $#idx ];

       Which could also be written this way, using a trick that's
       come to be known as the Schwartzian Transform:

           @sorted = map  { $_->[0] }
                     sort { $a->[1] cmp $b->[1] }
                     map  { [ $_, uc((/\d+\s*(\S+)/ )[0] ] } @data;

キモは、やはり trick の部分ではないでしょうか。JAPH と同じで。


Tokyo-pm メーリングリストの案内