[tpm] OID sorting

Uri Guttman uri at stemsystems.com
Sat May 2 21:01:28 PDT 2009


>>>>> "VP" == Viktor Pavlenko <vvp at cogeco.ca> writes:

  VP> Following the KISS directive:

keep it simple and SLOW?? :)

  VP> sub srt
  VP> {
  VP>     my ($a1, $a2) = map { [ split /\./ ] } @_;
  VP>     for (my $i = 0; $i <= $#$a1; ++$i) {
  VP>         return 1 unless defined $a2->[$i];
  VP>         return $a1->[$i] <=> $a2->[$i] unless $a1->[$i] == $a2->[$i];
  VP>     }
  VP>     return 0;
  VP> }

  VP> print sort { srt($a, $b) } @list, "\n";

you are doing ALL the heavy work inside the sort comparison. that is
O( N log N ) whereas with the map/sort/maps the heavy work is
O( N ). simple is not necessarily better. a bubble sort is the simplest
sort logic but never used on data set sizes above a few dozen.

uri

-- 
Uri Guttman  ------  uri at stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


More information about the toronto-pm mailing list