Randomness in built-in .sort
Bill Baxter
wbaxter at gmail.com
Mon Jan 5 13:41:30 PST 2009
On Tue, Jan 6, 2009 at 6:15 AM, dsimcha <dsimcha at yahoo.com> wrote:
> == Quote from Bill Baxter (wbaxter at gmail.com)'s article
>> Actually, a function to sort multiple arrays in parallel was exactly
>> what I was implementing using .sort. So that doesn't sound like a
>> limitation to me at all. :-)
>> --bb
>
> Am I (and possibly you) the only one(s) who think that sorting multiple arrays in
> parallel should be standard library functionality?
I use this all the time in NumPy in the form of "argsort" which
returns a list of indices giving the sort order. That can then be
used as to index other arrays (thereby permuting them to the sorted
order).
order = npy.argsort(keys)
sortedA = A[order]
sortedB = B[order]
> The standard rebuttal might be
> "use arrays of structs instead of parallel arrays".
> This is a good idea in some
> situations, but for others, parallel arrays are just plain better.
Yeh, that's just a silly argument. Sometimes a column-oriented
organization is more suitable than a row-oriented one.
Sort can be made to work on column-oriented data, so there's no reason
not to make it so.
> Furthermore, with D's handling of variadic functions, generalizing any sort to handle parallel
> arrays is easy.
Yeh, this works pretty nicely.
--bb
More information about the Digitalmars-d
mailing list