Python中有B树数据库或框架吗?

发布于 2024-09-26 20:49:33 字数 96 浏览 1 评论 0原文

我听说 B-Tree 数据库比哈希表更快,所以我想到在我的项目中使用 B-Tree 数据库。 python中是否有任何现有的框架允许我们使用这种数据结构,或者我必须从头开始编码?

I heard that B-Tree databases are faster than Hash tables, so I thought of using a B-Tree database for my project. Is there any existing framework in python which allows us to use such Data structure or will I have to code from scratch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

許願樹丅啲祈禱 2024-10-03 20:49:33

无论是在内存中还是在块存储中(如在数据库中),选择 B 树而不是哈希表的唯一原因是支持除相等以外的查询。 B 树允许您以良好的性能执行范围查询。不过,许多键值存储(例如 Berkley db)不会使其在外部可见,因为它们仍然对键进行哈希处理,但这仍然可以让您快速稳定地迭代整个数据集(即使有添加,迭代器仍然有效)或删除,或者必须重新平衡树)。

如果不需要范围查询,也不需要并发迭代,那么就不需要b树,使用哈希表,在任何规模上都会更快。

编辑:我曾经有过以上的情况确实是真的;为此, blist 包似乎是最完整的实现一个排序的容器库。

The only reason to choose a B-Tree over a hash table, either in memory or with block storage (as in a database) is to support queries other than equal. A b-tree permits you perform range queries with good performance. Many key-value stores (such as berkley db) don't make this externally visible, though, because they still hash the keys, but this still lets you iterate over the whole dataset quickly and stably (iterators remain valid even if there are adds or deletes, or the tree must be rebalanced).

If you don't need range queries, and you don't need concurrent iteration, then you don't need b-trees, use a hash table, it will be faster at any scale.

Edit: I've had occasion for the above to actually be true; for this, the blist package seems to be the most complete implementation of a sorted container library.

一梦浮鱼 2024-10-03 20:49:33

你真的应该看看zodb。
http://www.zodb.org/en/latest/

我写了一篇关于它很长一段时间,虽然它是西班牙语 http ://sourceforge.net/projects/banta/files/Labs/zodb/Monografia%20-%20ZODB.pdf/download

有很多英文信息。

you should really check out zodb.
http://www.zodb.org/en/latest/

i made a monography about it long go, though its in spanish http://sourceforge.net/projects/banta/files/Labs/zodb/Monografia%20-%20ZODB.pdf/download

There's plenty of information in english.

幽梦紫曦~ 2024-10-03 20:49:33

首先对您想要执行的操作进行编程,然后根据需要进行优化。时期。

编辑:

http://pypi.python.org/pypi/blist

替换 python 的内置版本在列表中。

Program what you are trying to do first, then optimize if needed. Period.

EDIT:

http://pypi.python.org/pypi/blist

Drop in replacement for python's built in list.

猫性小仙女 2024-10-03 20:49:33

SQLite3 在内部使用 B+ 树,但听起来您可能需要一个键值存储。尝试使用 Berkeley DB。如果您不需要事务,请尝试 HDF5。如果您想要分布式键值存储,还有 http://scalien.com/keyspace/,但这是一个服务器-客户端类型的系统,它将开放各种 NoSQL 键值存储。

所有这些系统的插入和检索时间复杂度都是 O(log(n)),因此它们可能比您当前使用的哈希表慢。

京都内阁提供了一个哈希树,所以这可能更多的是你所看到的,因为它应该是 O(1) 的插入和检索,但如果你需要的话,你不能进行中序遍历(尽管因为你目前正在使用哈希树,这不应该是问题)。

http://fallabs.com/kyotocabinet/

如果您正在寻找性能,则需要拥有速度关键项目以编译语言实现,然后在 Python 中拥有包装 API。

SQLite3 uses B+ Trees internally, but it sounds like you may want a key-value store. Try Berkeley DB for that. If you don't need transactions, try HDF5. If you want a distributed key-value store, there is also http://scalien.com/keyspace/, but that is a server-client type system which would open up all sorts of NoSQL key-value stores.

All of these systems will be O(log(n)) for insertion and retrieval, so they will probably be slower than the hash tables that you're currently using.

Kyoto Cabinet offers a hash tree, so that may be more of what you're looking at since it should be O(1) for insertion and retrieval, but you can't do in-order traversal if you need that (although since you're currently using hash trees, this shouldn't be an issue).

http://fallabs.com/kyotocabinet/

If you're looking for performance, you will need to have the speed critical items implemented in a compiled language and then have a wrapper API in Python.

青衫儰鉨ミ守葔 2024-10-03 20:49:33

这里有一个很好的btree纯python实现。如果需要,您可以对其进行调整。

Here there is a good btree pure python implementation. You can adapt it if needed.

瀞厅☆埖开 2024-10-03 20:49:33

您可能想看看 mxBeeBase 它是 eGenix mx 的一部分基地分布。它包括快速的磁盘 B+Tree 实现,并提供允许在 Python 中构建磁盘字典或数据库的存储类。

You might want to have a look at mxBeeBase which is part of the eGenix mx Base Distribution. It includes a fast on-disk B+Tree implementation and provides storage classes which allow building on-disk dictionaries or databases in Python.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文