A memory B+tree for Python3.
- store as list for same key
- range search
- delete key
Copy the folder bplus_tree
to your project.
from bplus_tree import BPlusTree
# Create a b+tree with b factor is 3
t = BPlusTree(3)
t.insert(1, 'Hello World!')
t.insert(7, 'a')
t.insert(7, 'b')
t.insert(3, 'c')
t.insert(5, '3')
>>> t.get(1)
['Hello World!']
>>> t.get(7)
['a', 'b']
or
>>> t[1]
['Hello World!']
>>> t[7]
['a', 'b']
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(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']
>>> 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'])]