节约B树到磁盘文件并阅读 [英] saving Btrees to a disk file and read it

查看:131
本文介绍了节约B树到磁盘文件并阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要救一个B树(不知道一个二进制)的磁盘文件。 然后读给存储器。 一些等级序遍历可能是一个二进制B树的好方法。 但是如果它不是一个二进制。 我从叶节点在内存中的RootNode建立B树。 我相信,我必须定义在磁盘文件和输出树节点部分的结构。 使用一些额外的标记,以确定在该文件中的一个节点? 如何遍历可能是关键的问题就在这里。 我coudn't想出一个好办法,以节省节点和指针。 然后阅读。 rconstruct在存储器中的树。 任何好的想法? 非常感谢。

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 not a binary one. I build up the Btree from the leafnode to the rootnode in memory. I believe that I have to define some structures in the disk file and output the tree nodes. using some extra tag to identify a node in the file? how to traversal may be the key problem here. I coudn't figure out a good way to save the nodes and the pointers. and then read it. rconstruct the tree in memory. any good ideas?. thanks a lot.

推荐答案

如果你真的想要做同样的事情,你可以指定每个节点的ID和保存节点的格式为:

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

[节点ID值左节点ID右节点ID]

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

然后访问树广度优先搜索。

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

当你想重建树,创建一个映射ID - >节点,然后读后退文件:所以,当你读一个记录,创建节点,它注册到地图,分配左和右节点读取节点从地图

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.

这篇关于节约B树到磁盘文件并阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆