Brian Kelley wrote:

Jean-Claude Wippler wrote:

Does anyone know how to do a multi-column sort, using column-wise permutations?

Is this the right approach? Thinking out loud here.


A multi-column sort is really a precedence sort. You only need to sort on a secondary or tertiary key if the primary key has equivalent values.

1) sort on next property
2) if any more properties groupby property else goto 4
3) foreach groupby subview go to 1
4) reassemble final indices

Result -> stable sort, I think :)

Yes, this is clear - and very much related, but quite what I mean.


I'm looking for ways to use more efficient algorithms underneath MK, ie. as basis to do the above. I'm also looking for ways to do things lazily - i.e. defer some of the computations. This could have considerable implications when you sort a view and then as for a slice of it, i.e. only display a small section of it.

I have a half-baked python implementation that requires an index column (mainly because the groupby method doesn't keep track of the row index)

The way this can be done is to add an extra column with row indices (sort of like APL's "iota") using the pair() operation, and then group. That way the result will carry original row indices with it.


There are more such tricks waiting to be found & exposed. I'm currently trying to better understand what sort of core functions are needed to build the rest with. Hence the Q about per-column sorting and trying to find a way to combine permutations.

To give an example - to sort on col 2, 4 reverse, and then 3 could be done using something like this:
m2 = sortmap(col[2])
m3 = sortmap(col[3])
m4 = sortmap(col[4])
result = view.remap(m3.remap(reverse(m4)).remap(m2))
(with partial use, i.e. when fetching only a slice of the result, all sorts of neat tricks can be added, leading to behavior which I think resembles what you are describing above)


Except that the above "permutation stacking" is not exactly right... alas.

-jcw

_____________________________________________
Metakit mailing list  -  [EMAIL PROTECTED]
http://www.equi4.com/mailman/listinfo/metakit

Reply via email to