English 中文(简体)
固定/功能数据结构的利用
原标题:Serializing persistent/functional data structures

持续的数据结构取决于效率结构的共享。 例如,见here

当我把数据结构序列化并写到档案或数据库时,我怎么能保持结构共享? 如果我只是狂妄地歪曲数据结构,我就会储存正确的价值,但我会失去结构共享。 因此,我能够把具有共同组成部分的数据结构保存到档案中,恢复数据,并且仍然拥有恢复数据中的大部分结构。

最佳回答

你们想要的是某种形式的洗衣。 这个问题已经得到充分的研究。 Andrew Kennedy s 的文件详细解释了如何在保持共享的同时进行序列化和分离。

问题回答

我认为,有两种明显的方法,它们又具有相关性。

  1. Don t serialize the structures, serialize the nodes. So, you d store a serialized record for each of the nodes in the example tree you gave, and you d convert all node references to a database key name for the node. This gives you sharing automatically, but has the cost of having to do multiple lookups chasing the references in order to load a structure.
  2. Color your nodes by ownership, like in your example. Have a concept of which structure a given node belongs to and only serialize the nodes in a structure that belong to that structure. Links to nodes in other structures get replaced by a reference to that structure and the node in question. This allows you to load an entire structure at once, but can cause you to have to load ALL related structures if they are highly interlinked.

选择这两种选择之间的选择取决于你如何优化,以及你期望在实践中看到何种联系。





相关问题
XML-RPC Standard and XML Data Type

I was looking at XML-RPC for a project. And correct me if I m wrong, but it seems like XML-RPC has no XML datatype. Are you supposed to pass as a string? or something else? Am I missing something? ...

Is it exists any "rss hosting" with API for creating feeds

I am creating a desktop app that will create some reports. I want to export these reports as RSS or ATOM feeds. I can easily create feeds with Rome lib for Java. But I have no idea how to spread them. ...

Improving Q-Learning

I am currently using Q-Learning to try to teach a bot how to move in a room filled with walls/obstacles. It must start in any place in the room and get to the goal state(this might be, to the tile ...

High-traffic, Highly-secure web API, what language? [closed]

If you were planning on building a high-traffic, very secure site what language would you use? For example, if you were planning on say building an authorize.net-scale site, that had to handle tons ...

Def, Void, Function?

Recently, I ve been learning different programming langages, and come across many different names to initalize a function construct. For instance, ruby and python use the def keyword, and php and ...

热门标签