[tpm] OID sorting

Uri Guttman uri at stemsystems.com
Fri May 1 13:30:51 PDT 2009


>>>>> "AH" == Abram Hindle <abram.hindle at softwareprocess.us> writes:

some comments on the packed sort. i haven't seen this code before.

  AH> #sort via cmp and packing
  AH> sub packsort {
  AH>  	#this is just a longform swartzian transform
  AH>  	my @packed = map { pack("${pack}*",@$_) } @_;
  AH>  	@packed == @_ or die "Packed and Data not same size";

why the check for data sizes each time? this is overhead that will kill
the speed. if the sort works, the data will be fine.

  AH>  	my @sortedpacked = sort { $a cmp $b} @packed;

no need for the explicit cmp op as string compare is the default for
sort. i think recent perls do optimize this away but it isn't needed
anyway.

  AH>  	@sortedpacked == @_ or die "SortedPacked and Data not same size";
  AH>  	my @sorted = map { [ unpack("${pack}*",$_) ] } @sortedpacked;
  AH> 	return @sorted

why don't you do this like you do the schwartzian, as one long
expression? the extra vars and size tests are slowing it down quite a
bit IMO.

this is an untested rewrite as a single expression:

sub packsort {

	return map [ unpack( "$pack*", $_ ) ],
	sort
	map pack( "$pack*", @{$_} ), @_ ;
}

IMO it is much easier to read. i removed some noise but added whitespace
too.

and you can generate several different sort styles with my Sort::Maker
module including a packed sort (called the GRT).

  AH> sub swartzpacksort {

his name is spelled schwartz! :) and it isn't a packed sort as the
intermediate values are in anon arrays.

thanx,

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