Re: Tree Collections...

Discussion in 'Java' started by Scott Hightower, Jul 5, 2003.

  1. JB wrote:

    > 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?
    >
    > Thanks.


    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
    need.

    However...

    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.

    Scott
    Scott Hightower, Jul 5, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug Poland
    Replies:
    9
    Views:
    705
    VisionSet
    Sep 27, 2003
  2. Ramkumar Menon

    B+ Tree versus Ternary Search Tree

    Ramkumar Menon, Aug 16, 2005, in forum: Java
    Replies:
    2
    Views:
    1,577
    Roedy Green
    Aug 16, 2005
  3. Ramkumar Menon

    B+ Tree versus Ternary Search Tree

    Ramkumar Menon, Aug 16, 2005, in forum: Java
    Replies:
    0
    Views:
    418
    Ramkumar Menon
    Aug 16, 2005
  4. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,081
  5. mutex
    Replies:
    0
    Views:
    193
    mutex
    Jul 27, 2003
Loading...

Share This Page