简体   繁体   English

如何将b树存储到光盘中?

[英]How to store a b-tree into disc?

I created a b-tree using Java in memory, which has get(K key), put(K key,V value) method, just like HashMap. 我在内存中使用Java创建了一个b树,它具有get(K key),put(K key,V value)方法,就像HashMap一样。 I had to store the b-tree into disc because the size becomes huge, Then I stored each node of tree as an file into disc, use file name to keep the pointer. 由于大小变大,我不得不将b树存储到磁盘中,然后将树的每个节点作为文件存储到磁盘中,使用文件名保留指针。 When doing search, only few files needed will be load into memory. 搜索时,只有很少的文件将被加载到内存中。 even though, I was not happy that a lot of files was created. 即使我不满意创建了很多文件。 any brilliant idea? 有什么好主意吗?

Use JSON: it is a very convenient way for serializing / deserializing data. 使用JSON:这是用于序列化/反序列化数据的非常方便的方法。

Using Jackson : 使用杰克逊

public static void writeToDisc(MyBTree myBTree, File file) throws IOException {
    new ObjectMapper().writeValue(file, myBTree);
}

public static MyBTree readFromDisc(File file) throws IOException {
    return new ObjectMapper().readValue(file, MyBTree.class);
}

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

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