【发布时间】:2021-08-20 01:05:29
【问题描述】:
在这里,我正在尝试创建其结构如下所示的图形数据库。随着我不断添加更多节点,我看不到 depth of the tree increasing。有人可以建议我在这里可能做错了什么吗?
A:1
/ \
B:2 C:3
/ \
D:4 E:5
>>> import lmdb
>>> env = lmdb.open("treedb.lmdb")
>>> txn = env.begin(write = True)
>>> txn.stat()
{'psize': 4096, 'depth': 0, 'branch_pages': 0, 'leaf_pages': 0, 'overflow_pages': 0, 'entries': 0}
>>> txn.put('root'.encode('utf-8'),json.dumps({'A':1}).encode('utf-8'))
True
>>> txn.stat()
{'psize': 4096, 'depth': 1, 'branch_pages': 0, 'leaf_pages': 1, 'overflow_pages': 0, 'entries': 1}
>>> txn.put('A'.encode('utf-8'), json.dumps({'A':{'B':2}}).encode('utf-8'))
True
>>> txn.stat()
{'psize': 4096, 'depth': 1, 'branch_pages': 0, 'leaf_pages': 1, 'overflow_pages': 0, 'entries': 2}
>>>
>>> txn.put('A'.encode('utf-8'), json.dumps({'A':{'C':3}}).encode('utf-8'))
True
>>>
>>> txn.stat()
{'psize': 4096, 'depth': 1, 'branch_pages': 0, 'leaf_pages': 1, 'overflow_pages': 0, 'entries': 3}
>>>
>>> txn.put('B'.encode('utf-8'), json.dumps({'B':{'D':4}}).encode('utf-8'))
True
>>> txn.put('C'.encode('utf-8'), json.dumps({'C':{'E':5}}).encode('utf-8'))
>>> txn.stat()
{'psize': 4096, 'depth': 1, 'branch_pages': 0, 'leaf_pages': 1, 'overflow_pages': 0, 'entries': 5}
【问题讨论】:
-
我不断添加更多孩子,但树仍然保持平坦。几乎它只是一个键:值数据库而不是图形。我一定遗漏了一些我不明白的东西。
-
只需要遍历查询吗?或者你还需要按属性查询?
-
只遍历查询