|We don't bite newbies here... much|
|( #3333=superdoc: print w/replies, xml )||Need Help??|
(I am not fanatic about efficiency and I am aware of the usual caveats about premature optimization. But I think this makes an interesting subject for a meditation.)
I know of Guttman & Rosler's article about sort. In it they argue in favour of using sort's "internal sort" i.e. without an explicit sort sub.
The technique consists in packing both the key on which to sort on (lexicographically) and the original data into strings and to recover the original data later.
But this may not be always/easily applicable e.g. if the items to be sorted are complex data structures themselves. So I thought that one may still take advantage of the fast "internal" sort doing something like this:
(the second form may even be cast into a single statement like thus:
but that wouldn't probably make for much clarity.)
Update: it occurs to me now thatis even simpler and not that unreadable. Probably it's the best of all the code examples given here... well as far as my taste is concened!
Whatever, I have never seen such techniques before and I'm curious to hear some comments about them. I have not done any benchmark yet and I'm also looking for some suggestions about possibly interesting target cases.
In reply to RFC: yet another sorting technique by blazar