将 BTree 序列化到文件

发布于 2024-08-14 06:51:57 字数 150 浏览 11 评论 0原文

我正在尝试实现 BTree。我已经完成了树的工作,并且对于较小的输入非常有效,这意味着我已经在内存中实现了树。现在我想使用大输入,我必须将树写入文件。我不知道从哪里开始。我正在使用 Java,并且没有做过太多的“磁盘写入”编码。任何帮助将不胜感激。如果有人想帮助我举一个例子那就更好了。

I'm trying to implement a BTree. I'm pretty much done with the tree and works great for a smaller input which means I've implemented the tree in memory. Now I would like to play with large input for which I've to write the tree to a file. I don't know where to get started. I'm using Java and I haven't done too much of 'disk write' coding. Any help would be very appreciated. If someone wants to help me with an example that would be even better.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单调的奢华 2024-08-21 06:51:58

您可能想看看这个问题

You might want to take a look at this question.

动听の歌 2024-08-21 06:51:57

如果您的 BTree 及其节点实现 Serialiable,则可以使用 ObjectOutputStream 和 FileOutputStream 将树及其内容写入文件。测试起来很容易:将其写入 .ser 文件,然后读回,然后查看是否已恢复原始 BTree。

Java Almanac 有一些很好的示例,可以提供帮助。

更新:我没有看到您在进行修改时动态写入的用例,也没有看到“不想写入整个树”。

你所建议的似乎慢得难以置信。将内存中的每个更改镜像到文件的相应修改将需要很长时间。

如果您尝试执行自己的数据库实现,这是有意义的。您想到什么场景?

If your BTree and its Nodes implement Serialiable, you can write the tree and its contents to a file using ObjectOutputStream and FileOutputStream. It'll be easy to test: write it out to a .ser file, read it back in, and see that you've got the original BTree back.

Java Almanac has some nice examples by package that'll help.

UPDATE: I'm not seeing either your use case for writing dynamically as modifications are made or "not wanting to write the whole tree."

What you're suggesting seems impossibly slow. Mirroring each change in memory with a corresponding modification to the file will take a long time.

If you're trying to do your own database implementation this makes sense. What scenario do you have in mind?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文