You could potentially emulate the Perl way using the macros and
functions.

See the perlapi (perldoc) for:
sortsv - to do the sort (doh!)
hv_iterkeysv - to grab the keys, and av_push to build the array for
sorting.
# warning - example stolen from tt2 code
    AV *result = newAV();
    HE *he;
    hv_iterinit(hash);
    while ((he = hv_iternext(hash))) {
        av_push(result, SvREFCNT_inc((SV *) hv_iterkeysv(he)));
    }

sortsv(AvARRAY(result), av_len(result)+1, Perl_sv_cmp_locale);


Or something similar (there are other sorts in pp_sort.c I think).

Cheers.




On Mon, Mar 07, 2005 at 01:13:24PM -0500, [EMAIL PROTECTED] wrote:
> Hi Guys
> 
> I am re-implementing a perl subroutine in C and this perl-subroutine 
> sorts the key of a hash given to it as input before using it. This hash 
> usually hold about 3000-4000 keys.  So I am wondering what to do here:
> 
> 1) Create another hash in perl-space and sort its keys using the perl 
> sort() function and then pass that hash as input
> 2) Write my own sort function or, even better, use one from a better 
> source like the Gnu Scientific Library or another third party library.
> 
> So, what I am basically asking is if it is worth replaceing perl's sort 
> function with another one in inlined space or not ?
> 
> Thanks !
> Nitin

-- 
http://www.piersharding.com
http://search.cpan.org/~piers/

Reply via email to