tags:

views:

347

answers:

5

Hello,

I'm looking for a non visual persistent tree (TStringTree) implementation. If someone known any good implentation of it, please let me know.

Thanks.

+2  A: 

What kind of tree? B-tree? Splay tree? Red-black tree? These are all common types of tree algorithms.

You might want to look at Julian Bucknall's book, Tomes of Delphi: Data Structures and Algorithms. It has all sorts of tree implementations with full Delphi source; you could easily adapt any of them to work with strings.

Ken White
This looks more about binary trees indexes etc. I'm looking for something more trivial and it's a tree implementation. Because the VCL has a lot of different lists (tlist, tcollection, etc) but no one tree implementation.
Francis Lee
You can use balanced and unbalanced trees for more than indexing... What exactly are you trying to do? What use is a tree structure non-visually, other than being able to organize the data in order to be able to search it (therefore the common use for indexing)?
Ken White
In my opinion, a tree implementation is good in a lot of circustances. The VCL is plenty of non visual list and full of visual trees. But there isn't a base class for a tree which could be a good start for some other classes. For example a directory structure, or all the internet stuff like HTML, XML, JSON, etcIn my case I want to use it to get parts of a content at different levels.
Francis Lee
A: 

Why not simply use an XML DOM document?

It may be overkill for a truly trivial string-tree, but would not be too burdensome to use for that purpose and has the benefit of being capable of accommodating just about any extension to a string-tree (for storing additional data with each string in the tree - as attributes etc) should the need arise.

In my experience often what starts out as a trivial need can quickly grow beyond the initial or anticipated requirement. :)

If you are concerned about the "overhead" of the COM based XML implementation and the VCL wrapper around it, you might look into TNativeXML

Deltics
Basically I'm looking for a tree implementation without any reference of Json or XML, only the barebone.
Francis Lee
+1  A: 

You could just use a tStringList and add objects which are other tStringLists... crude, but it works if your data can be represented as only string data.

Child := tStringlist.create;
ParentList.AddObject('Child',Child);

Of course a better solution would be to create your own objects which contain a tobjectlist of objects.

skamradt
+3  A: 

You'll find a flexible, non-visual tree structure in the DI Containers library (commercial). However, as others have noted above, it's really quite easy to roll your own, adding only the functionality that you need.

You can do with just two base objects: TNode and a TNodeList (e.g. a TObjectList descendant). At minimum, TNode needs just three members: your string data, a reference to its parent node (nil if the node is root), and a TNodeList, which is a list of its child nodes. What remains is the (somewhat tedious) implementation of the various attendant methods such as Add(), Delete(), IndexOf(), MoveTo(), GetFirstChild(), GetNext() etc. The basic tree should be less than a one-nighter.

moodforaday
That's why I referred him to the Bucknall book; it has implementations of trees, linked lists, etc., and I thought it might provide alternatives.
Ken White
@Moodfaraday. Thanks, this is an easy way. But it is has no persistence behavior
Francis Lee
@Francis: I missed the "persistent" requirement indeed, sorry. The DI Containers library does have persistence built in, via SaveToStream/LoadFromStream methods for all its data structures. I have not used DI Containers myself, but I use three other components from the same vendor, all highly reliable in my experience.
moodforaday
+2  A: 

And of course there is still the funky DECAL (previously Rosetta), an attempt at creating a kind of STL using interfaces and variants.

http://sourceforge.net/projects/decal/

More for the people that flexibility over speed though. The base tree structure is Red-Black iirc.

Marco van de Voort