I don\'t know if this is the place to ask about algorithms. But let\'s see if I get any answers ... :)
If anything is unclear I\'m very happy to clarify things.
Look at : Judy-arrays and the python interface at http://www.dalkescientific.com/Python/PyJudy.html