saving Btrees to a disk file and read it

后端 未结 4 1102
后悔当初
后悔当初 2020-12-03 06:32

I want to save a Btree(not sure a binary one) in a disk file. and then read it to the memory. some Level-order traversal may be a good way for a binary Btree. but if it is n

4条回答
  •  广开言路
    2020-12-03 06:56

    If you really want to do something similar, you can just assign at each node an id and save the nodes in that format:

    [node-id value left-node-id right-node-id]

    and then visit the tree with a breadth-first search.

    When you want to reconstruct the tree, create a map id->node and then read backward the file: so, when you read a record, create the node, register it to the map and assign the left and right node fetching the nodes from the map.

提交回复
热议问题