Re: Need a faster Find Duplicates Routine
Re: Need a faster Find Duplicates Routine
- Subject: Re: Need a faster Find Duplicates Routine
- From: Paul Skinner <email@hidden>
- Date: Tue, 27 May 2003 16:27:42 -0400
On Tuesday, May 27, 2003, at 02:58 PM, Johnny AppleScript wrote:
Hey All,
Anyone know of any samples that will run faster than this?
snip
My 'ItemIndex' handler can be put to this purpose.
I came up with ItemIndex, a tids-based-list-index handler, back in the
dark days before OS X. I'm sure that it would now be better handled in
Perl.
This handler will break with more than 4000+- occurances of one of the
search terms.
set theIndex to {}
set list1 to {"a", "b", "c", "d"}
set list2 to {"a", "aa", "A", "c", "a", "a", "b", "c", "c", "etc",
"bb", "c", "c"}
repeat with currentSearchTerm in list1
set the end of theIndex to {currentSearchTerm as text,my
ItemIndex({searchTerm:currentSearchTerm, inputList:list2})}
end repeat
theIndex-->{{"a", {1, 5, 6}}, {"b", {7}}, {"c", {4, 8, 9, 12, 13}},
{"d", {}}}
on ItemIndex(parameters)
set pd to AppleScript's text item delimiters
set rareDelimiter to "o#?"
set thisIndex to 0
set indices to {}
set AppleScript's text item delimiters to {""}
set searchTerm to rareDelimiter & searchTerm of parameters &
rareDelimiter
set inputList to inputList of parameters
set AppleScript's text item delimiters to rareDelimiter & rareDelimiter
set inputList to ({rareDelimiter} & inputList & {rareDelimiter}) as
list
set AppleScript's text item delimiters to {rareDelimiter &
rareDelimiter}
set inputList to inputList as text
set AppleScript's text item delimiters to {""}
set AppleScript's text item delimiters to searchTerm
set inputList to (every text item of inputList as list)
set occurances to (length of inputList) - 1
set previousItemsIndex to 0
set AppleScript's text item delimiters to {rareDelimiter &
rareDelimiter}
repeat with iteration from 1 to occurances
if item iteration of inputList is rareDelimiter & rareDelimiter then
set subItems to 1
else
if item iteration of inputList is "" then
set subItems to 0
else
copy (text 2 thru -2 of (item iteration of inputList)) to
thisSublist
set thisSublist to every text item of thisSublist
set subItems to (length of thisSublist)
end if
end if
set thisOccurancesIndex to previousItemsIndex + subItems
set the end of indices to thisOccurancesIndex
set previousItemsIndex to thisOccurancesIndex + 1
end repeat
set AppleScript's text item delimiters to pd
return indices
end ItemIndex
_______________________________________________
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.