简体   繁体   中英

Storing a tree structure in java

I want to pre-compute some moves for my Game AI and store them on the disk, to be loaded at runtime. The moves are stored in a quinary tree and I'd appreciate it if you could recommend me some libraries that could let me to easily save them and restore them.

使用Java的序列化机制来持久化树是最简单的解决方案,并使用ObjectInputStream读取/ ObjectOutputStream来从磁盘写入序列化数据/将磁盘写入序列化数据。

As mentioned in the previous answers, you can make your tree implement the Serializable and let the JVM do everything for you (make sure all node classes are Serializable as well)

public class Tree implements Serializable{
   Node rootNode = ...

}

If your tree contains a large amount of data then you could probably trim down all the data that can be re-calculated when the tree is reloaded from disk, have a look at the Momento design pattern to get an idea on how this can be acheived.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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