[erlang-questions] orddict (was Re: OO programming style in Erlang?)

Robert Virding <>
Fri Jan 26 02:54:06 CET 2007


Ulf Wiger wrote:
> Den 2007-01-25 03:26:16 skrev Richard A. O'Keefe <>:
> 
>>The orddict module is extremely unusual in having the same interface
>>as the dict module.
> 
> So does the ordsets module have the same interface as the sets module.

Yup, it sure does. Both pairs were designed to have the smae interfaces, 
dict and orddict, sets and ordsets.

>> However, it does NOT have the same PERFORMANCE
>>characteristics.  So once again, if you want to have any idea how well
>>your code is likely to work, you had BETTER know which version you are
>>using.  (And wouldn't it be nice if the documentation said something
>>about performance?)  In fact, there really aren't that many places that
>>you would want to use orddict at all.
> 
> 
> I can think of one good reason to use ordsets/orddict: debugging.
> 
> It is decidedly more enjoyable to watch (trace/debugging)
> printouts of ordsets and orddicts compared to sets/dicts.
> Pretty-printing of large dicts in the shell is in fact
> everything but pretty.
> 
> Personally, I use ordsets quite often. I seldomly use orddict,
> however, but if I do it is exactly for the reason above, and
> in cases where performance is not critical.

Orddict and ordsets are better when the number of elements is small. 
They are much lighter structures and faster to set up. Dict and sets are 
much heavier objects more tuned to a large number of elements. I once 
managed to get over 800000 elements into a dict, but it wasn't fast.

And sometimes it is practical to have a simple well designed data 
structure. Apart from being easier to read when printed. :-)

I have a dream! What I would really like is a dict with the access 
functions written in C. That would rock! If the internal structures were 
normal erlang tuples and lists like today then it would be easy to 
implement some functions in erlang, like fold and map, and some in C, 
like fetch and store. The best of both worlds. It would be good base to 
implement Ets in erlang using processes and eliminating all synch 
problem in SMP.

Robert



More information about the erlang-questions mailing list