Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Feature request: two level sorting

On 16 June 2016 at 09:21, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> So what you're really suggesting is --
> Given two arrays AA and AB which must be of equal length:
> (1) sort AB and apply that new ordering to the elements of AA
> (2) except that if two elements of AB are the same, use another
>     sort to order the corresponding elements of AA
> -- and you want a syntax that passes the name of AB, the order to be
> applied to AB, and the secondary order of AA, via the expansion flags
> of a reference to AA.
> Have I got it this time?

I think yes. Not sure how tricky GROUP BY sorting is, but it sounds tricky.

> What if you need "two levels" of sorting for the desired order AB?

Yeah that's an issue. But that's least we can do, GROUP BY sorting on
one group. What's important in this, is that it will allow to avoid
O(N^2) situations. Ultimate solution would be own comparing code,
thing used e.g. C++ where it has proven to be well abstract, allowing
to face variety of demands, rather all of them. What I'm really hoping
is that the (x:groups:) flag would be similarly elastic, resulting in
uses that are hard to predict. But I cannot provide any trick that
(x:groups:) would allow.

Also, own comparing code would be rather slow? Zsh doesn't do
compilation I think, so it would evaluate the code at each comparison,
so that's a drawback. (x:groups:) wouldn't have this issue. And it
could open door to variety of O(N^2)-avoid tricks.

PS. Could the (x:groups:) array contain multiple groups separated via
available-separator e.g. ":"? I mean, one can have objections to mess
with his original data adding prefix separated with ":". That's why
I've chosen the imperative way of solving, the loop mentioned. Didn't
want to mess with data, change way it looks and track this with
extensive thought. But I could surely mess with separate groups array,
it would feel natural to provide "A:1:x" there and similar
sub-group-pretending things.

Best regards,
Sebastian Gniazdowski

Messages sorted by: Reverse Date, Date, Thread, Author