Re: Dynamic Records?? (or other alternatives)
Re: Dynamic Records?? (or other alternatives)
- Subject: Re: Dynamic Records?? (or other alternatives)
- From: Arthur J Knapp <email@hidden>
- Date: Fri, 30 Nov 2001 15:55:11 -0500
>
Subject: Re: Dynamic Records?? (or other alternatives)
>
From: email@hidden (Michael Sullivan)
>
Date: Thu, 29 Nov 2001 13:19:06 -0500
>
Another solution is to check out Arthur Knapp's AssociativeLib on
>
www.applemods.com. This library has functions to create and manipulate
>
an object (whose internal representation is two lists, one with key
>
names and one with values) that functions like a record but which can
>
have new keys added on the fly from variable values.
Any potential user of AssociativeLib should be aware of an issue
that has arisen, (and which has not yet been corrected).
The script uses two variable names that have caused name-space
proplems in the Smile script editor, (and possibly in others as
well). You should change "labels" and "values" to less generic
words, such as, "theLabels" and "theValues".
>
... I've now used this
>
a couple times.
Fantastic.
A number of great vanila methods for acomplishing this have been
posted in the past. Check out these emulated hash techniques:
<
http://www.esglabs.com/snippets/map.sit.hqx>
<
http://files.macscripter.net/ScriptBuilders/ScriptTools/hashLib.hqx>
Another method that I once posted is here:
<
http://archives:email@hidden/mhonarc/applescript-users/msg14908
.html>
Walter Ian Kaye claims to have done something similar, but the proof
is in the pudding...
;-)
>
Does anyone know if getting/setting the value of a record key is O(1) in
>
Applescript? If so, that would be a good reason to seek out the hackish
>
solution for your script, since the O(n) behavior of lists would start
>
to show on long pieces of text for your word count (your program would
>
end up O(n^2)).
The problem of using big O notation in AppleScript is that things occur
on two different levels, the AppleScript-algorithmic level and the C/C++/
Pascal level, meaning the code that underlies AppleScript.
Consider the difference between the these snippits:
on is_contained(aList, aItem)
repeat with x from 1 to length of aList
if item x of aList = aItem then return true
end
return false
end
is_contained( myBigList, myItem ) --> true/false
myBigList contains myItem --> true/false
It is a good bet that these two "commands" are both doing more
or less the same thing, traversing myBigList until it finds a
match, or not, but it is also a good bet that for even large N,
the "contains" syntax is going to always be lightning fast
compared to is_contained, making a big O comparison between them
irrelevent.
P.S. I'm still just a scripter... ;-)
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
<
mailto:email@hidden>
try
<
http://www.appleklub.cz/~koudelka/home.shtml>
on error number -128
end try
}