Skip to content

Nero5023/bplustree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

BPlusTree

A memory B+tree for Python3.

Features

  • store as list for same key
  • range search
  • delete key

QuickStart

Copy the folder bplus_tree to your project.

Create a BPlusTree object

from bplus_tree import BPlusTree
# Create a b+tree with b factor is 3
t = BPlusTree(3)

Insert key value pair

t.insert(1, 'Hello World!')
t.insert(7, 'a')
t.insert(7, 'b')
t.insert(3, 'c')
t.insert(5, '3')

Retrieve value from tree through key

>>> t.get(1)
['Hello World!']
>>> t.get(7)
['a', 'b']

or

>>> t[1]
['Hello World!']
>>> t[7]
['a', 'b']

Range search

range_search(self, notation, cmp_key)

range search compare with cmp_key

notation supports '>' '<' '>=' '<='

>>> t.range_search('>', 3)
['3', 'a', 'b']
>>> t.range_search('>=', 3)
['c', '3', 'a', 'b']

Search

search(self, notation, cmp_key)

search compare with cmp_key

notation supports '>' '<' '>=' '<=' '!=' '=='

>>> t.search('==', 3)
['c']
>>>  t.search('!=', 3)
['Hello World!', '3', 'a', 'b']
>>> t.search('>', 3)
['3', 'a', 'b']
>>> t.search('>=', 3)
['c', '3', 'a', 'b']

Keys, values and item pairs

>>> t.keys()
[1, 3, 5, 7]
>>> t.values()
['Hello World!', 'c', '3', 'a', 'b']
>>> t.items()
[(1, ['Hello World!']), (3, ['c']), (5, ['3']), (7, ['a', 'b'])]

About

In memory b+tree implementation for python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages