Re: Tree Collections...
> I have looked at Java's TreeSet and TreeMap, but their usage seems to be
> pretty much the same as a HashMap.
> What should I use for a real hierarchical tree structure (red-black, play,
> etc...).with directly accessible nodes?
> TreeMap's documentation says that it is an implementation of a red-black
> tree, but you cannot directly access child nodes, parent, etc...
> Any suggestions?
I'm curious about what problem you're solving that needs this capability.
Sometimes it helps to tell us the context, not just the solution you think you
I wanted something like this awhile back, because I was implementing a Ternary
Search Tree and wanted to display the internal structure (to see if it was
working as expected). IIRC, TreeMap is similar enough to apply my solution:
extend TreeMap (call it VisibleTreeMap, if you will) and add interfaces to
give you access to the internal structure. For display purposes, it's
probably sufficient to walk the tree from the root each time you need to
refresh the display (unless it's a really big tree). If you really need
efficient parent access, you may be able to override the internal class used
for the nodes and add a reference to parent. You will also have to override
the code that inserts nodes. (That's if there isn't already a parent
reference--I don't remember if there is, but you can figure it out pretty
quickly looking at the code.)
Beats writing your own full implementation from scratch--maybe.
|All times are GMT. The time now is 04:52 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.