--On 6. Dezember 2005 14:55:08 +1300 Cameron Beattie <[EMAIL PROTECTED]> wrote:

I want to do this frequently and at low cost i.e. ideally in memory.
Perhaps the best way is to write a procedure in MySQL however I am
interested in any python-based alternatives.

Your problem is more an algorithmic problem than q question of the data representation. Store the mapping as some BTree (possibly IIBTree using normalized integers for the values). Then you have to iterate over all prefixes of the dialed number starting with the longest prefix to the smallest prefix. Then perform a lookup of the prefix in your BTree...
this is should not take more than five lines of code and requires a maximum
of #(length_of_dialed_number) comparisons. If you want it more complicated construct a tree and you'll have a logarithmic number of comparisons. I doubt that it is worth the effort since the first solution should be fast enough unless your dialed number is hundreds of digits long :-)


Attachment: pgp2ARghXrI2q.pgp
Description: PGP signature

Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to