• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Picking data from a record
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Picking data from a record


  • Subject: Re: Picking data from a record
  • From: has <email@hidden>
  • Date: Sat, 25 Sep 2004 13:18:05 +0100

Joseph Weaks wrote:

The Types library at AppleMods <http://applemods.sourceforge.net/mods/Data/Types.php> provides 'Dict' objects as a vanilla alternative. Example:

What is the difference between a Dictionary object and an Associative List as you use them in your Types library?

Efficiency. Both store keys and values in internal lists, but use different strategies to locate keys. The documentation looks a bit vague about the relative advantages and disadvantages of the two types, so here's a quick explanation:


The Types library's AssociativeList object uses a simple linear search to find values by key, so worst-case scenario is it has to compare N keys to find the right one, where N is the number of items. It's the dumbest solution, but has the advantage that it can use any kind of object that supports is-equal-to comparisons as a key.

The Dictionary object stores keys in order, allowing it to use a binary ('divide and conquer') search to locate a given key, so at worst it has to compare log(N) keys. Smarter, but relies on all keys being objects that also support direct less-than and greater-than comparisons, so must store all keys as unicode text.

To summarise: the Dictionary object is much faster for getting and setting existing items than the AssociativeList object. The Dictionary is much less efficient at adding items with new keys, however, and can only use text-based keys. Each object provides a different mix of pros and cons; there's no simple 'one size fits all'. Deciding which one to use in a particular situation means weighing their relative pros and cons against the task's requirements and picking the one you find fits those requirements best. e.g. If your code spends most of its time getting and setting existing items rather than adding new ones and doesn't need to use stuff like lists or references as keys, use a Dictionary. If it spends most of its time collecting new values and only rarely needs to look one up, an AssociativeList may be best. If you're writing a multi-window Studio app and want to look up a window's Controller object by using that window's reference as a key, use an AssociativeList [1].

Hope that clarifies,

has

[1] Example: <http://freespace.virgin.net/hamish.sanderson/MVCExampleProject.sit>
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
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
References: 
 >Re: Picking data from a record (From: has <email@hidden>)

  • Prev by Date: Re: keystroke using ... { } ... in PowerMail
  • Next by Date: Fwd: Replacing in TextEdit
  • Previous by thread: Re: Picking data from a record
  • Next by thread: Re: Picking data from a record
  • Index(es):
    • Date
    • Thread