用于 Python 的磁盘 B+ 树 3
Bplustree ============ .. image:: https://travis-ci.org/NicolasLM/bplustree.svg?branch=master :target: https://travis-ci.org/NicolasLM/bplustree .. image:: https://coveralls.io/repos/github/NicolasLM/bplustree/badge.svg?branch=master :target: https://coveralls.io/github/NicolasLM/bplustree?branch=master 一个存储在磁盘上的 B+ 树,用于 Python 3。它感觉像一个字典,但存储在磁盘上。何时使用它? - 当要存储的数据不适合内存 - 当数据需要持久化 - 当保持键的顺序很重要 此项目正在开发中:文件的格式可能在不同的版本之间发生变化。请不要将其作为主要数据源使用。 快速入门 ---------- 使用 pip 安装 Bplustree: pip install bplustree 创建一个存储在文件上的 B+ 树索引,并使用它: .. code:: Python
从 bplustree 中导入 BPlusTree tree = BPlusTree('/tmp/bplustree.db', order=50) tree[1] = b'foo' tree[2] = b'bar' tree[1] b'foo' tree.get(3) tree.close() 键和值
键必须具有自然顺序,并且必须可序列化为字节。某些默认键 提供了用于最常见类型的序列化器。例如,用于索引 UUID: .. 代码:: Python
导入 uuid 从 bplustree 中导入 BPlusTree 和 UUIDSerializer tree = BPlusTree('/tmp/bplustree.db', serializer=UUIDSerializer(), key_size=16) tree.insert(uuid.uuid1(), b'foo') list(tree.keys())
另一方面,值总是以字节为单位。它们可以具有任意长度,参数 value_size=128 定义了可以存储在树中本身的值大小的上限。超过此限值的值将存储在溢出页中。每个溢出的值至少占用一整页。
[UUID('48f2553c-de23-4d20-95bf-6972a89f3bc0')] 1 2
暂无开放 Issues,或尚未同步最近议题。