in reply to Re: Re: Re: Re: sorting a vec
in thread sorting a vec
There is no way to use the perl's built-in sort to achieve your goal.
If your storing 32-bit integers in a string, then you effectively have a C-style array of ints. It would therefore be fairly easy (assuming that you compile your own perl) to use Inline::C to get at the base address of that C-style array, ie. the base address of the scalar, and use your C-RTL's qsort() routine to do the sorting. This would be far quicker than any Perl solution.
If you use a binary distribution of perl, then it would still be possible, though awkward, to use the C-RTL qsort(). Getting the base address of the scalar can be done with pack, and (assuming AS perl), it should be possible to use Win32::API to get the entrypoint for qsort(). The problem then would be providing a callback address for the comparison function. Possibly possible :), but awkward and fragile. Mapping the pointers the qsort function gives to the compare function from one string to valid pointers into another would be possible, but messy.
I had a play with implementing a pure perl qsort using vec to get at the individual integers. It works, and could be used to sort one string based upon the contents of another (although I'm not entirely sure I understand what you mean by that), but it wouldn't be quick by any stretch of the imagination.
I tried it on 100,000 ints and it took a little under 5 minutes, which is an order of magnitude slower than using sort on a standard array. For contrast, the C-RTL qsort() function will do 1,000,000 in 4 seconds. I'm afraid that this is one of those things that there is simply no substitute for getting closer to the metal and using C or assember.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Re: sorting a vec
by Anonymous Monk on Mar 28, 2004 at 02:10 UTC | |
by BrowserUk (Patriarch) on Mar 28, 2004 at 04:37 UTC |