简体   繁体   English

类似于Python的boost :: multi_index

[英]Something like boost::multi_index for Python

I have come to appreciate a lot boost::multi_index in C++. 我已经开始在C ++中欣赏了很多boost :: multi_index。 It happens that I would happily use something like that in Python; 碰巧我很乐意在Python中使用类似的东西; for scripts that process data coming out from numerical intensive applications. 用于处理来自数字密集型应用程序的数据的脚本。 Is there such a thing for Python? 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. 在Python中包装boost :: multi_index。 It simply doesn't scale. 它根本无法扩展。

  • Using sqlite3 in memory. 在内存中使用sqlite3。 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. 由于python集合只存储对象的引用,而不存储对象本身,因此将一个集合与多个索引方案和只有多个集合之间的区别并不大。

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. 为了回答你在Python中是否存在类似事物的问题,我会说不。

One useful feature of Boost.MultiIndex is that elements can be modified in-place (via replace() or modify()). Boost.MultiIndex的一个有用特性是可以就地修改元素(通过replace()或modify())。 Python's native dict doesn't provide such a functionality and requires the key to be immutable. Python的本机字典不提供这样的功能,并且要求密钥是不可变的。 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. 所以在这个特定领域,没有与Python中的Boost.MultiIndex类似的东西。

If you only require multiple static views of your data, then I would agree with Radomir Dopieralski. 如果您只需要多个静态数据视图,那么我同意Radomir Dopieralski。 You can wrap multiple dicts in your own class to provide a unified API to ensure the synchronization between different views. 您可以在自己的类中包装多个dicts,以提供统一的API以确保不同视图之间的同步。 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." 我不知道“性能感知转换”是什么意思,但如果你在谈论插入/删除操作的计算复杂性,即使使用Boost.MultiIndex,“将元素插入到multi_index_container中也会简化为一个简单的组合对每个指数进行基本插入操作,类似地删除。“

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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