Click here to get back home

[ANN] Sort::Key 0.02

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
[ANN] Sort::Key 0.02 Salvador Fandino 04-28-2005
Posted by Salvador Fandino on April 28, 2005, 11:02 am
Please log in for more thread options


Hi,

I have released Sort::Key 0.02, a module for sorting objects by some key.

It's really fast, usually much faster than perl core sort function and
even than other popular methods like the Schwartzian or the GRM
transforms (and BTW, easier to use).


Comments, bug reports, etc., are welcome!


The docs follow...

NAME
Sort::Key - Perl extension for sorting objects by some key

SYNOPSIS
use Sort::Key;

@by_name = keysort { "$_-> $_->" } @people;
@by_age = nkeysort { $_-> } @people;
@by_sons = ikeysort { $_-> } @people;

DESCRIPTION
Sort::Key provides a set of functions to sort object
arrays by some (calculated) key value.

Usually, it is faster and uses less memory than other
alternatives implemented around perl sort function.

EXPORT
This package exports these functions:

keysort { CALC_KEY } @array
returns the elements on @array sorted by the key
calculated applying "{ CALC_KEY }" to them.

Inside "{ CALC_KEY }", the object is available as
$_.

For example:

@a=({name=>john, surname=>smith},
{name=>paul, surname=>belvedere});
@by_name=keysort } @a;

lkeysort { CALC_KEY } @array
similar to keysort but takes into account locale
configuration when comparing keys.

nkeysort { CALC_KEY } @array
similar to keysort but compares the keys numerically
instead of as strings.

ikeysort { CALC_KEY } @array
similar to keysort but automatically converts the
keys to integer values and compares them
numerically.

SEE ALSO
perl sort function

AUTHOR

COPYRIGHT AND LICENSE
Copyright (C) 2005 by Salvador Fandino

This library is free software; you can redistribute it
and/or modify it under the same terms as Perl itself,
either Perl version 5.8.4 or, at your option, any later
version of Perl 5 you may have available.



Posted by peter pilsl on April 28, 2005, 8:39 pm
Please log in for more thread options


Salvador Fandino wrote:
>Comments, bug reports, etc., are welcome!

a first test is impressive:

create 0.09837
sort1 0.638449 <- perl-sort
sort2 0.116141 <- your sort


best,
peter


#!/usr/bin/perl -w

use Time::HiRes qw(gettimeofday tv_interval);
use Sort::Key;

my $t0 = [gettimeofday];
print "createt";
my $x;
foreach (0..20000) {
$x->=rand();
}

$elapsed = tv_interval ( $t0 );
print $elapsed,"n";
$t0 = [gettimeofday];

print "sort1t";
my @r1=sort <=> $x->} (0..20000);
$elapsed = tv_interval ( $t0 );
print $elapsed,"n";
$t0 = [gettimeofday];

print "sort2t";
my @r2=nkeysort } (0..20000);
$elapsed = tv_interval ( $t0 );
print $elapsed,"n";
$t0 = [gettimeofday];





--
http://www.goldfisch.at/know_list


Similar ThreadsPosted
ANNOUNCE: Sort::Maker .02 September 2, 2004, 5:09 am
Sort::Maker : anonymous sub is compiled outside of my module December 5, 2006, 8:25 am
Accomodate for poor db design using Sort::Maker? December 9, 2006, 12:48 am
Sort::Maker: style => 'plain' difficulty December 14, 2006, 4:35 am
Sort::Maker: (Notes) The plain and the orcish don't include the "init_code" December 14, 2006, 7:32 am
Win32::OLE::Const 'Microsoft Excel' - sort & freeze pane April 30, 2008, 12:48 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap