I want to use Cython to compile a Python module that works with a dictionary of which all keys are of type, say, integer (or no matter what other static and known type), and all values of type unicode (or other static and known).
Now, to speed it up, I can declare
cdef dict Dict
and also
cdef int k
cdef unicode v
But, can I make a static declaration of the whole "dict int->unicode" structure?
Thanks,
I think the short answer is no. Cython is still using the built-in Python dictionary. It can take advantage of some optimisations if you declare the object as dict, but ultimately the dict has to be able to store objects of different types, and so you cannot specify the key or value types at compile-time. But you should check first to make sure that this is a bottleneck. Python dictionaries are fairly good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With