Re: Sort hash keys in C...

Rudolf Lippan <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.sybase.devel
Message-ID <[email protected]>
On Tue, 22 Apr 2008 11:24:17 +0100, Tim Bunce <[email protected]> wrote:
> The DBI needs to sort the keys in %$attr for connect_cached and
> prepare_cached to ensure a canonical cache key is generated.
> 
> Currently this is done in perl and is relatively expensive:
> 
>     my @attr_keys = ($attr) ? sort keys %$attr : ();
>     my $key = do { local $^W; # silence undef warnings
>         join "~~", $dsn, $user, $auth, $attr ? 
> (@attr_keys,@{$attr}{@attr_keys}) : ()
>     };
> 
>     my @attr_keys = ($attr) ? sort keys %$attr : ();
>     my $key = ($attr) ? join("~~", $statement, @attr_keys,
> @{$attr}{@attr_keys}) : $statement;
> 
> I'd like to wrap that up into a _concat_hash_keys( \%hash, $separator,
> \@extras )
> function implemented in C..
> 
> As part of that we'd need a function to return the keys of a hash in
> sorted order. That just needs to allocate an array of char*'s, load it
> with pointers to each of the keys in the hash, and then call qsort().
> 
> The bonus is that that function would enable the ParamValues reported by
> ShowErrorStatement to be listed in sorted order:
>     http://rt.cpan.org/Ticket/Display.html?id=27272
> (function could take a flag to indicate lexical or numeric sort order)
> 
> Any volunteers, either for both or just the sort function?
> 

Hi Tim,

I would be happy to take a crack at them tomorrow -- actually I have a
rough draft implementation that I will work on cleaning up and testing. 

-r
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.