简体   繁体   English

在磁盘内存中实现树结构

[英]Implementing Tree Structure in disk memory

I am writing some data to a text file(stored in disk) as output from my program. 我正在将一些数据写到文本文件(存储在磁盘中)作为程序输出。 I want to organize the data in the text file in a search tree format so that it facilitates efficient search and replace(through the program itself). 我想以搜索树格式组织文本文件中的数据,以便它(通过程序本身)促进有效的搜索和替换。 I would like to know how to implement the tree structure to be stored in a disk memory. 我想知道如何实现要存储在磁盘存储器中的树形结构。

One of the main practical difficulties of using a tree data-structure on disk is that with naive binary trees data will be "far apart" and trying to access this data will likely cause thrashing as your hard drive attempts to continuously access different locations on disk. 对使用磁盘上的树数据结构的主要实际困难是,与天真的二叉树数据将是“相距甚远”,并试图访问该数据很可能会造成颠簸的硬盘驱动器试图继续访问磁盘上的不同位置。

The classic solution to this problem is to use B-trees . 解决此问题的经典方法是使用B树 The basic idea behind B-trees is that reads from disk are expensive so you should use them as little as possible. B树的基本思想是,从磁盘进行读取非常昂贵,因此应尽可能少地使用它们。 This is accomplished by using large nodes; 这是通过使用大型节点来完成的。 instead of storing only two children, B-trees can have m children. B树可以容纳m个孩子,而不是只存储两个孩子。 This greatly increases the entropy of each node meaning that it takes far fewer reads to access you data. 这大大增加了每个节点的熵,这意味着访问数据所需的读取次数少得多。

Some more reading on B-trees can be found here , the pictures are particularly helpful in my opinion, and several implementations on B-trees can be found here . 此处可以找到有关B树的更多信息,我认为这些图片特别有用,并且可以在此处找到有关B树的几种实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM