Re: Determining item number matching "x" in a list
Re: Determining item number matching "x" in a list
- Subject: Re: Determining item number matching "x" in a list
- From: Emmanuel <email@hidden>
- Date: Fri, 14 Mar 2003 01:37:40 +0100
At 2:08 AM +0000 12/03/03, Nigel Garvey wrote:
Here's a sketch from a
project I shelved last year. If you need case sensitivity, put the call
to the handler in a 'considering case' block.
on getIndex of theItem into theList
-- The braces are necessary when checking that the item
-- is 'in' the list, to enable nested lists to be found
set searchItem to {theItem}
if theList does not contain searchItem then return 0
-- A list variable in a script object, for speed of access to its
items
script o
property pList : theList
end script
-- If the item is in the list, use a binary search to locate it
set L to 1
set R to (count theList)
repeat until theItem is item L of o's pList
set L to L + 1
set M to (L + R) div 2
if searchItem is in (items L thru M of o's pList) then
set R to M
else
set L to M + 1
end if
end repeat
return L
end getIndex
(follow-up of my previous mail)
NG's "getindex" requires 170 +or- 25 microseconds
My "IndexOfItem" requires 809 +or- 37 microseconds
Emmanuel
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.