Storing values

Discussion in 'Java' started by Michael, Feb 22, 2004.

  1. Michael

    Michael Guest

    Hi,

    I would like to store values in the form of this:

    (rootNode, childNode1)
    (rootNode, childNode2)
    (rootNode, childNOde3)
    ....

    What sort of collection type can I use in this case? I have looked
    into Hashtable, and it seems to overwrites to the last inserted data
    when providing the same Key (rootNode).

    Any help from you guys will be greatly appreciated.

    Thank You.
     
    Michael, Feb 22, 2004
    #1
    1. Advertising

  2. Michael

    Tony Morris Guest

    "Michael" <> wrote in message
    news:...
    > Hi,
    >
    > I would like to store values in the form of this:
    >
    > (rootNode, childNode1)
    > (rootNode, childNode2)
    > (rootNode, childNOde3)
    > ...
    >
    > What sort of collection type can I use in this case? I have looked
    > into Hashtable, and it seems to overwrites to the last inserted data
    > when providing the same Key (rootNode).
    >
    > Any help from you guys will be greatly appreciated.
    >
    > Thank You.


    You want to use a data structure known as a BTree.
    Java does provide support for this ADT in the core API; you'll have to write
    it yourself.

    --
    Tony Morris
    (BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
    Software Engineer
    IBM Australia - Tivoli Security Software
    (2003 VTR1000F)
     
    Tony Morris, Feb 22, 2004
    #2
    1. Advertising

  3. Michael

    Bjorn Abelli Guest

    "Michael" wrote...

    > I would like to store values in the form of this:
    >
    > (rootNode, childNode1)
    > (rootNode, childNode2)
    > (rootNode, childNOde3)
    > ...
    >
    > What sort of collection type can I use in this case?


    That depends on how you actually are going to use the "collection".

    > I have looked into Hashtable, and it seems to
    > overwrites to the last inserted data when
    > providing the same Key (rootNode).


    Yes of course, as Hashtable is a collection based on the concept of
    "key-value-pair" (*one* key to *one* value), to speed up the search for what
    value that is associated to a specific key.

    But it doesn't seem like that really is what you want, as you try to store
    "children" to a "root", i.e. not a 1:1-relation but a 1:m-relation.

    Possibly you're looking for the "other way around":

    (childNode1, rootNode)
    (childNode2, rootNode)
    (childNode3, rootNode)

    ....which is possible to use as a "lookup" to see which root a child belongs
    to (if a child only can belong to one root at a time).

    It could also be possible that you really not are looking for a "Collection"
    at all, but rather a "datamodel", which it in this case looks like, e.g. a
    "TreeModel" such as "DefaultTreeModel".

    In the end, which "collection" you need isn't depending on what type you
    "can" use, but rather on "how" you will use it.

    // Bjorn A
     
    Bjorn Abelli, Feb 22, 2004
    #3
  4. Michael

    ak Guest

    I would like to store values in the form of this:
    >
    > (rootNode, childNode1)
    > (rootNode, childNode2)
    > (rootNode, childNOde3)
    > ...
    >
    > What sort of collection type can I use in this case? I have looked
    > into Hashtable, and it seems to overwrites to the last inserted data
    > when providing the same Key (rootNode).


    I use similar thing in my project ImageroReader - it called HashBag.
    it uses simple idea - each key in Hashtable corresponds to Vector which
    contains all values for this key.

    --

    ____________

    http://reader.imagero.com the best java image reader.
     
    ak, Feb 22, 2004
    #4
    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. Clemens
    Replies:
    1
    Views:
    506
    Mike Treseler
    Jan 29, 2005
  2. Hazzard
    Replies:
    4
    Views:
    3,273
    Hazzard
    Jul 9, 2003
  3. abdul bari
    Replies:
    1
    Views:
    463
    Stanley
    Aug 29, 2003
  4. toton
    Replies:
    11
    Views:
    712
    toton
    Oct 13, 2006
  5. Jonathan Wood
    Replies:
    1
    Views:
    511
    Jonathan Wood
    Jun 2, 2008
Loading...

Share This Page