TechNewsHeaven {{source.name}}




NicolasLM/bplustree
2018-01-21T19:37:33.631146Z - NicolasLM / Hacker News
BplustreeAn on-disk B+tree for Python 3. QuickstartInstall Bplustree with pip:pip install bplustreeCreate a B+tree index stored on a file and use it with:>> > from bplustree import 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()Keys and valuesKeys must have a natural order and must be serializable to bytes. For example to index UUIDs:>> > import uuid >> > from bplustree import BPlusTree, UUIDSerializer >> > tree = BPlusTree( ' /tmp/bplustree.db ' , serializer = UUIDSerializer(), key_size = 16 ) >> > tree.insert(uuid.uuid1(), b ' foo ' ) >> > list (tree.keys()) [UUID( ' 48f2553c-de23-4d20-95bf-6972a89f3bc0 ' )]Values on the other hand are always bytes. If tree doesn't get closed properly (power outage, process killed...) the WAL file is merged the next time the tree is opened. It is best to keep it close to the block size of the disk cache_size to keep frequently used nodes at hand.

Your favorite news


Popular news




Recommended news