Re: An alternative to "sort" & "uniq"
Re: An alternative to "sort" & "uniq"
- Subject: Re: An alternative to "sort" & "uniq"
- From: "Gary (Lists)" <email@hidden>
- Date: Mon, 18 Apr 2005 09:03:00 -0400
Martin Orpen wrote [4/18/05 7:23 AM]:
> on 18/4/05 11:02, Gary (Lists) at email@hidden wrote:
>
>> Martin Orpen wrote [4/18/05 5:47 AM]:
>>
>>> If you keep the random number maximum equal to or less than the number of
>>> items in the list the result appears to always be returned sorted.
>>>
>>> I¹m sure that there must be a method of returning the minimum & maximum
>>> items
>>> from the list, but couldn¹t work out how :-(
>>
>> If you've convinced yourself that, given your suggested restraints, the
>> values are returned sorted, then the min is item 1 and the max is last item,
>> eh?
>
> I only tested it a few times - so I'm not totally convinced and the method
> therefore cannot be relied upon to get the min value.
I sounded more "sassy" than intended, upon reading. I just meant "if you're
pretty sure". And you're not, so.
> There must be an obj-c method which grabs the min value without the need to
> sort the entire array. I just can't find it...
>
> Also, I'm thinking that it might be interesting to see if populating an
> array using some kind of obj-c method is faster than using vanilla AS?
I don't know from C, but you might want to consider the following as both a
possible AS-native alternative to sorting and uniqueness, and as a
comparative tool if you do decide to explore ObjC vs. AS comparisons.
The appleMods 'List' library has over two dozen (well, 25 ;) commands for
dealing with lists. Some of those are related to rapid-fire sorting of
lists [1] and many more to further kinds of list processing.
The Library is sufficiently well-thought to provide a mechanism for passing
list items off to any user-defined callback handlers for even more
fine-tuned processing (I am thinking about uniqueness here, where you could
shuffle new items onto a new list object, or already-existing items onto
another, or whatever -- including processing mathematically, for min/max.)
The full command list and read me as text, and a download link [2], are at
SourceForge, here:
<http://applemods.sourceforge.net/mods/Data/index.php>
Then see the 'List' entry.
(I don't deep-link to the exact page here, because I just realize that
unless you come at the page this way, there is not a link _back_ to the full
list. Oops.)
These Libraries are CrossMOS (9/X), at least up to the X/AS versions at
their release. (We'll see in a couple of weeks, right?)
--
Gary
[1] The current version ('s author) makes a choice between dealing with
mixed class lists (think text vs. number comparison) and speed/complexity.
The choice is for speed, and so lists must have items of the same class.
However, there are 4 handlers for working with data type and so you can
pre-filter lists by making decisions with:
isAllSameClass(lst) -- is every item in list the same class?
isAllOfClass(lst, theClass) -- is every item in list of a particular class?
isAllNumbers(lst) -- is every item in list a number (integer or real)?
isAllText(lst) -- is every item in list a text value (string or Unicode)?
[2] All 'appleMods' Libraries also require the Loader, so you'll need to D/L
that as well. See the 'Getting Started' section at the site home.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden