Re: Sorting a list of records
Re: Sorting a list of records
- Subject: Re: Sorting a list of records
- From: "Mark J. Reed" <email@hidden>
- Date: Mon, 23 Aug 2010 20:10:52 -0400
You could pick an efficient, stable algorithm from the table at
http://en.wikipedia.org/wiki/Sorting_algorithm#Comparison_of_algorithms
and implement it. Or modify an existing one - the most efficient form
of QuickSort is not stable, but if you're willing to pay a time and
space penalty you can alter the partitioning algorithm to make it
stable, as described in its own Wikipedia entry (linked from its entry
in the above table).
If your records can be represented as single lines of text with some
sort of single-character delimiter between fields, you could use 'do
shell script "sort -s" '.
On Mon, Aug 23, 2010 at 6:58 PM, Gil Dawson <email@hidden> wrote:
> Hi, Folks--
>
> I need an algorithm to sort a list of records in a "stable" way. By "stable", I mean
>
> When two keys are equal, output records are in the same order as the input.
>
> The AppleScript 'CustomQsort' algorithm suggested by Adam Bell, Nigel Garvey, et al in (http://macscripter.net/viewtopic.php?id=17340) works well in my application except that the underlying QuickSort algorithm is intrinsically not "stable".
>
> I looked at the "sortlist" command in Satimage.osax. It is stable, but it sorts a list of lists, instead of a list of records. I would need to figure a way to "coerce" a list of records to a list of lists, then back again.
>
> Anyone have another idea?
>
> --Gil _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden