Beispiel #1
0
    os.remove("database/homework03.db")
if os.path.exists("database/homework03.db-wal"):
    os.remove("database/homework03.db-wal")

tree = BPlusTree('database/homework03.db',
                 key_size=32,
                 order=5,
                 serializer=StrSerializer())
tree

# ### 1. Insert: key, value 쌍을 tree index에 삽입
# * 삽입 과정에서 leaf node와 parent node의 split을 확인할 수 있다.

# In[2]:

tree.insert('a', b'1')
tree.insert('b', b'2')
tree.insert('c', b'3')
tree.insert('d', b'4')
tree.display()

tree.insert('e', b'5')
tree.display()

# In[3]:

tree.insert('f', b'6')
tree.insert('g', b'7')
tree.insert('h', b'8')
tree.insert('i', b'9')
tree.insert('j', b'10')
def demo_bplustree():
    print('Initializing B+ tree...')
    bplustree = BPlusTree()

    print('\nB+ tree with 1 item...')
    bplustree.insert('a', 'alpha')
    bplustree.show()

    print('\nB+ tree with 2 items...')
    bplustree.insert('b', 'bravo')
    bplustree.show()

    print('\nB+ tree with 3 items...')
    bplustree.insert('c', 'charlie')
    bplustree.show()

    print('\nB+ tree with 4 items...')
    bplustree.insert('d', 'delta')
    bplustree.show()

    print('\nB+ tree with 5 items...')
    bplustree.insert('e', 'echo')
    bplustree.show()

    for i in range(20):
        print('\nB+ tree with ' + str(i + 5) + ' items...')
        bplustree.insert(str(i), 'foxtrot' + str(i))
        bplustree.show()

    print('\nRetrieving values with key e...')
    print(bplustree.query('e'))