Author Topic: What's the difference between a Dictionary and a Symbol Table?  (Read 6290 times)

0 Members and 1 Guest are viewing this topic.

SIDESHOWBOB

  • Guest
What's the difference between a Dictionary and a Symbol Table?
« on: November 20, 2012, 10:53:51 AM »
Just asking..?

Lee Mac

  • Seagull
  • Posts: 12892
  • London, England
Re: What's the difference between a Dictionary and a Symbol Table?
« Reply #1 on: November 20, 2012, 11:00:34 AM »
As far as I know, where functionality is concerned there is not too much difference; Symbol Tables were only retained when Dictionaries were implemented for legacy reasons.

But Irneb knows more:

http://www.theswamp.org/index.php?topic=42110.msg473109#msg473109
http://www.theswamp.org/index.php?topic=41936.msg470518#msg470518

Jeff H

  • Needs a day job
  • Posts: 6141
Re: What's the difference between a Dictionary and a Symbol Table?
« Reply #2 on: November 20, 2012, 11:09:47 AM »
From the docs:
 
Comparison of Symbol Tables and Dictionaries

Symbol tables and dictionaries perform essentially the same function; they contain entries that are database objects that can be looked up using a text string key. You can add entries to these container objects, and you can use an iterator to step through the entries and query their contents.
 
The AutoCAD database always contains a fixed set of nine symbol tables, described in the following section. You cannot create or delete a symbol table, but you can add or change the entries in a symbol table, which are called records. Each symbol table contains only a particular type of object. For example, the AcDbLayerTable contains only objects of type AcDbLayerTableRecord. Symbol tables are defined in this manner mainly for compatibility with AutoCAD Release 12 and previous releases of AutoCAD.
 
Dictionaries provide a similar mechanism for storing and retrieving objects with associated name keys. The AutoCAD database creates the named object dictionary whenever it creates a new drawing. The named object dictionary can be viewed as the master “table of contents” for the nonentity object structures in a drawing. This dictionary, by default, contains nine dictionaries: the GROUP dictionary, the MLINE style dictionary, the layout dictionary, the plot style name dictionary, the color dictionary, the material dictionary, the plot settings dictionary, the table style dictionary, and the SYSVAR dictionary. You can create any number of additional objects and add them to the named object dictionary. However, the best practice is to add one object directly to the named object dictionary and have that object in turn own the other objects associated with your application. Typically, the owning object is a container class such as a dictionary. Use your assigned four-letter Registered Developer Symbol for the name of this class.
 
An AcDbDictionary object can contain any type of AcDbObject, including other dictionaries. A dictionary object does not perform type checking of entries. However, the MLINE style dictionary should contain only instances of class AcDbMlineStyle, and the GROUP dictionary should contain only instances of AcDbGroup. An application may require specific typing for entries in a dictionary that it creates and maintains.
 
The class hierarchy for symbol tables, symbol table records, dictionaries, and iterators is as follows.

An important difference between symbol tables and dictionaries is that symbol table records cannot be erased directly by an ObjectARX ® application. These records can be erased only with the PURGE command or selectively filtered out with wblock operations. Objects owned by a dictionary can be erased.
 
  Warning Erasing dictionaries or dictionary entries (see Essential Database Objects) probably will cause AutoCAD or other applications to fail.   Another important difference is that symbol table records store their associated look-up name in a field in their class definition. Dictionaries, on the other hand, store the name key as part of the dictionary, independent of the object it is associated with, as shown in the following figure.
 

 

SIDESHOWBOB

  • Guest
Re: What's the difference between a Dictionary and a Symbol Table?
« Reply #3 on: November 20, 2012, 11:13:40 AM »
That's good to know, thanks.

Another question - do dictionary reads take O(log n) time as their name implies?

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: What's the difference between a Dictionary and a Symbol Table?
« Reply #4 on: November 20, 2012, 12:41:00 PM »
Possibly.  But anything I'd use dictionaries for would be small enough that access time isn't a consideration.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: What's the difference between a Dictionary and a Symbol Table?
« Reply #5 on: November 21, 2012, 06:37:57 AM »
Another question - do dictionary reads take O(log n) time as their name implies?
I'm not too sure how ACad implments its dictionaries. If they use the standard Dictionary collection in C++/C# then it's actually O(1) time ... since those dictionaries are implemented using Growable Reference Arrays with a hashing index.

Anyhow, basically Jeff's indicated all the differences. For me the major ones are:
  • You can make your own dictionary, but not your own symbol table (unless you do some ObjectARX).
  • A dictionary can be attached to any object inside the DWG, not just as a global dictionary to the DWG. That way you can add dictionaries to (say) a layer, or a line. These will then live with that object - i.e. copied / erased together with its owner. For this you need xdata if not using dictionaries.
But seeing a Sym Tabl's are onyl built-in stuff ... there's no real choice in the matter. You use them when you need to get at blocks/layers/etc. You use dictionaries when you want to get at settings saved there (e.g. Annotative Scales), or when you want to make your own set of settings.
 
Edit: added links to C++/C# standard library dictionaries.
« Last Edit: November 21, 2012, 06:41:27 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.