简体   繁体   中英

Something like boost::multi_index for Python

I have come to appreciate a lot boost::multi_index in C++. It happens that I would happily use something like that in Python; for scripts that process data coming out from numerical intensive applications. Is there such a thing for Python? I just want to be sure that it doesn't exist, then I would try to implement it myself. Things that won't do it for me:

  • Wrapping boost::multi_index in Python. It simply doesn't scale.

  • Using sqlite3 in memory. It is ugly.

Since python collections only store references to objects, not objects themselves, theres isn't much difference between having one collection with multiple indexing schemes, and just having multiple collections.

You can for example have several dicts with your data, each of them using different keys to refer to them.

To answer your question of whether a similar thing exists in Python, I would say no.

One useful feature of Boost.MultiIndex is that elements can be modified in-place (via replace() or modify()). Python's native dict doesn't provide such a functionality and requires the key to be immutable. I haven't seen other implementations that allow the key to be altered. So in this specific area, there's no comparable thing as Boost.MultiIndex in Python.

If you only require multiple static views of your data, then I would agree with Radomir Dopieralski. You can wrap multiple dicts in your own class to provide a unified API to ensure the synchronization between different views. I don't know what you mean by "performance-aware transformations" but if you were talking about the computational complexity of the insertion/deletion operations, even with Boost.MultiIndex, "inserting an element into a multi_index_container reduces to a simple combination of elementary insertion operations on each of the indices, and similarly for deletion."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM