[asterisk-dev] Associative Arrays in the Dialplan

Steve Murphy murf at digium.com
Fri Jun 1 23:05:52 MST 2007

In a branch, team/murf/datastructs, I implemented 
associative arrays via a hashtable. I call it a hashtab;
I have a set of funcs that allow it to be used from the dialplan. 

There's nothing HASHTAB can do, that you can't do with astdb.
Hashtabs aren't persistent, don't create or use any files, are hopefully
lighter weight and hopefully faster.

I put together a standalone program to test the hashtab locking in 
a multi-threaded environment. It takes 1 arg, the number of threads
to pound it with, and each thread will call out 100,000 random
on the hashtab. (70% chance of a lookup, 20% chance of an addition, 10%
of a removal). All threads brutalize the same hashtab. Hashtabs have
locking; it uses read/write locking, so a bunch of readers can access it
simultaneously without a problem.

The func interface to hashtabs use a string key, and a string value.
(The underlying hashtab can store any kind of object, and use any kind
of key.)
You can specify whether you want the keys to be case-sensitive or not,
an initial size for the table. The func interface asks the hashtab
to use locking, and to resize itself automatically to keep lookups
optimally fast.

Using keys like "1" or "2" or "133", you can get the same effect as
using arrays.

There's documentation in doc/.

Please review, and let me know what you think. Any feedback on the code
and how badly I've muffed things will be appreciated.

No, I haven't compiled the docs with latex yet. No, it's not completely
finished, but it is close to finished.


Steve Murphy
Software Developer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3227 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20070601/dc2d4eb7/smime.bin

More information about the asterisk-dev mailing list