将 Btrees 保存到磁盘文件并读取它 [英] saving Btrees to a disk file and read it

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

问题描述

我想在磁盘文件中保存一个 Btree(不确定是二进制的).然后将其读入内存.一些Level-order 遍历对于二叉Btree 可能是一个好方法.但如果它不是二进制的.我在内存中建立了从叶节点到根节点的 Btree.我相信我必须在磁盘文件中定义一些结构并输出树节点.使用一些额外的标签来标识文件中的节点?如何遍历可能是这里的关键问题.我想不出保存节点和指针的好方法.然后阅读它.在内存中构建树.有什么好主意吗?非常感谢.

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.

推荐答案

B-Trees 的常用技术是确保节点的大小等于磁盘的块大小,并 mmap 磁盘文件.您没有指定您正在使用哪种编程语言,因此它可能像 C 中的强制转换一样简单,或者更复杂,例如创建享元对象来包装 java.nio.IntBuffer.无论哪种方式,B 树的大部分优点是您不必一次加载它,但可以相当有效地跳过它.

The usual technique for B-Trees is to ensure that the size of a node is equal to the block size of the disk, and mmap the disk file. You don't specify what programming language you're working in, so it might be as simple as a cast in C, or something more complicated such as creating flyweight objects to wrap up a java.nio.IntBuffer. Either way, much of the advantage of the B-tree is that you don't have to load it all at once, but can jump around it fairly efficiently.

这篇关于将 Btrees 保存到磁盘文件并读取它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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