用于建模包含/组合关系的数据结构

huangapple go评论109阅读模式
英文:

Data structure for modelling a containment/composite relation

问题

我在golang邮件列表中发布了一条类似的消息,因为它涉及一些特定于语言的细节。我希望语言本身的并发支持可能有比模式更好的建模方式。如果您对golang不熟悉,请帮助我了解一般数据结构方面的知识。我认为我的大部分疑问都是与语言无关的,并且我在SO上得到了更好的回应。

我正在尝试建模一个存储区域(具有包含关系,如存储->架子->货架->箱子)。
据我所了解,通常可以使用“组合模式”来建模。但是,为了

  • 将结构(层次结构)细节与对象分开
  • 使用语言结构(通道遍历树等)
    我考虑将信息建模成一棵树。我不知道哪种树结构最适合这个应用程序。
  1. 在go中,我看到有两个库实现了LLRB和treap。你会推荐哪个?是否有更适合的数据结构可用?
  2. 树是否需要平衡?例如,一个架子中可能只有一个货架,但其他架子中的包含关系可能任意长。
  3. 为了快速遍历,我将其保存在内存中。如何管理加载、构建和持久化树结构?我是否每次打开应用程序时都要构建树,而不是持久化树本身而是对象。
英文:

I posted a similar message in golang mailing list, as it involve some language specific details. I hope the cuncurrency support native to the language may have a better way to model this than a pattern. If you are not familar with golang, please help me with your knowledge of data structure in general. I think most of my doubts are lanuage neutral and I had better response from SO.

I am trying model a storage area (has a containement relation like, storage -> Rack(s) -> Shelf(s) -> Bin(s).
As I learned, typically it may model with "composite pattern". But, in an effort to

  • Keep the structural (hierarchy) details seperate from objects
  • Use the language constructs (channels to walk the tree etc)
    I was thinking of modelling the information in a tree.I do not have an understanding of what is the best tree structure suitable for this application.
  1. In go, I see two libraries implementing LLRB and treap. What would you recommend? Is there a more suitable data structure available?
  2. Does the tree has to be balanced? for example, I may have only ine shelf in one rack, but can be arbitrariy long containment in others.
  3. For quick traversal, I will keep it in memory. How do I manage loading, building and persisting the tree structure? Do I build the tree everytime I open the application, and do not persist the tree itself but the objects.

答案1

得分: 0

你在Go-Nuts列表上得到了很好的答案。Sameer Ajmani建议从内置类型开始是很好的。在简单的解决方案证明不足以解决问题之前,不要陷入更复杂的东西。Si guy有你的持久化解决方案。Gob快速而简单。

英文:

You got good answers on the Go-Nuts list. Sameer Ajmani's advice to start with built in types is good. Don't get bogged down in something more complex until simple solutions prove inadequate. Si guy has your solution for persistence. Gob is fast and simple.

huangapple
  • 本文由 发表于 2012年3月25日 23:38:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/9861420.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定