什么数据结构最适合VirtualStringTree? [英] What data structure is best suited for VirtualStringTree?

查看:406
本文介绍了什么数据结构最适合VirtualStringTree?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我猜,曾经使用过Delphi的VirtualStringTree的人都会同意这是一个很好的控制。它是一个虚拟控件(您的数据必须位于其他位置),所以我在想什么数据结构是最适合这样的任务?数据结构必须支持层次结构,它必须快速,轻松地扩展。最简单的实现将是使用一个记录,这是大多数可以找到的文档是建议。但是如果你需要做一些快速查找,计算总计等呢?您与VirtualStringTree一起使用的数据结构?



EDIT1 :我使用的是Delphi 2010。



好的,我会尽量给出更多有关我的要求的细节。
数据大小可以非常变量,从1到数千项。每个项目可以保存多个字符串,整数值。我需要随机访问,我的数据可以在应用程序生命周期内多次更改。良好的性能是非常可取的。我还需要数据保存和重新加载。



EDIT2
有1个答案,所以我会尝试评论我的意见。谢谢Dorin你的答案,但
我不认为你的结构非常方便。
1)它不处理层次结构。
2)为每个节点分离TStringList或TList不是非常有效的IMO。有了这个实现,我只能查找当前节点的数据,但不能在整个树中有效搜索。



我认为这个数据结构必须像一棵树。它必须具有添加子节点的节点。然后我可以在OnInitNode事件中获取节点的数据,检查我的节点是否有一些孩子,如果是,则设置ivsHasChildren标志,然后在OnInitChildren事件中设置正确的孩子计数。稍后在OnGetText事件中,我可以从我的节点结构中获取所需的数据,并根据Column索引将其设置为CellText。我的想法是具有单独的数据结构,并且无需使用VirtualStringTree来执行所有需要的操作。希望有人得到我的观点:)。



EDIT3 :我发现了相当有趣的JclTrees单元,它可以用来实现什么我在找。它属于 JCL 库。缺乏体面的文档使得很难快速调查其功能。当我有更多的时间时,我可能会深入了解它。

解决方案

好的,因为给定的答案没有解决我的问题,我写了我自己的树数据结构,模拟TVirtualStringTree和处理我在问题中提到的所有问题。现在我可以选择使用我的数据结构,其中的所有更改将自动更新VirtualStringTree。我想我会在以后的某个地方上传源代码,并在这里发布链接。感谢所有的答案。



编辑:我已经将资源上传到Google代码: svTrees 。有一个演示,演示如何运作。


I guess everyone who had ever used Delphi's VirtualStringTree will agree that it is a great control. It is a "virtual" control (your data must be held somewhere else) so I was thinking what data structure is the best suited for such a task? IMO that data structure must support hierarchy, it must be fast and easily expandable. The easiest implementation would be using a record and that's what most of the documentation which can be found is suggesting. But what if you need to do some fast lookups, calculate totals, etc? What data structure you are using together with VirtualStringTree?

EDIT1: I'm using Delphi 2010.

OK, I'll try to give some more details about my requirements. Data size can be very variable, from 1 to thousands of items. Each item can hold multiple string, integer values. I need random access, my data can change many times during the application lifetime. Good performance is very desirable. I also need data saving and reloading.

EDIT2: Got 1 answer so I'll try to comment my opinion. Thanks, Dorin for your answer but I don't think your structure is very convenient. 1) It doesn't deal with hierarchy. 2) Having separate TStringList's or TList's for each node is not very effective IMO. With this implementation I can only lookup the current node's data, but can't effectively search in the whole tree.

I think this data structure must be like a tree. It must have nodes with ability to add children. Then I just could get node's data in OnInitNode event, check if my node has some children, set ivsHasChildren flag if so, then in OnInitChildren event set correct children count. Later in OnGetText event I could just fetch needed data from my node structure and set it to CellText based on the Column index. My idea is to have a separate data structure and do all the needed operations with it without a need to use VirtualStringTree. Hope someone got my point :).

EDIT3: I've found quite interesting JclTrees unit which at first sight could be used to achieve what I'm looking for. It belongs to JCL library. Lack of decent documentation makes it hard to quickly investigate it's functionality. I'll probably look deeper into it when I have some more time.

解决方案

OK, because given answers didn't solved my issues I've written my own tree data structure which imitates TVirtualStringTree and handles all the problems I mentioned in my question. Now I can optionally use only my data structure and all the changes in it will automatically update the VirtualStringTree. I think I will upload source code somewhere later and post the link here. Thanks for all the answers.

EDIT: I've uploaded source to the Google code: svTrees. There is a little demo that shows how it works.

这篇关于什么数据结构最适合VirtualStringTree?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆