• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

passing 2D collection objects into 1D collection objects

when, where, how, why we need to passing 2D collection objects like hashmap, hashtable, properties into 1D collection objects like arraylist, vector, hasset, sorted set etc  and reading back again. What are the practical uses, advantages, disadvanages of doing it.Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
0
gudii9
Asked:
gudii9
  • 2
1 Solution
 
sweetfa2Commented:
Generally this sort of thing is done when you want to extract all of the keys, or all of the values and do something with them and the key is no longer relevant.

Depending on what processing you want to do with the list will depend on how effective or extra processing is required.  For example, if you are deleting a whole lot of items from a large dictionary, it may be quicker to extract all the values to a list and remove the items from  the list and then recreate the dictionary/hashmap.

Sometimes you can do this sort of thing to rebalance a TreeMap or something similar where aver time the tree becomes unbalanced because a lot of work is happening on a few node groups.
0
 
gudii9Author Commented:
>>Sometimes you can do this sort of thing to rebalance a TreeMap or something similar where aver time the tree becomes unbalanced because a lot of work is happening on a few node groups.


can you please elaborate on above point. I am not clear on that.
0
 
sweetfa2Commented:
Think of a tree as a set of roots for a tree.

As things get added to the tree they get added to one side or the other of the tree depending on where they fall between the existing nodes.  If you delete a lot of nodes from one side of the tree roots, then it is like cutting of one set of branches of a tree.  The tree no longer has the same number of nodes (branches/root branches) evenly spaced over a tree.

A similar thing happens when lots of additions occur between the keys that sit on one side of the tree.  That side of the tree becomes unbalanced and a tree search needs to descend further nodes to find the correct key value.  This slows down the performance of a tree.

Most tree algorithms will have a capacity to rebalance, some automatically, some manually to adjust the nodes of the tree back to something approximating equality.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now