aspose file tools*
The moose likes Java in General and the fly likes Hashtables in java might confuse the general hashtable understanding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hashtables in java might confuse the general hashtable understanding" Watch "Hashtables in java might confuse the general hashtable understanding" New topic
Author

Hashtables in java might confuse the general hashtable understanding

Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi

For sometime I have been wondering that Hashtable concept implemented in Java might be little confusing with general hashtable concept.

Not that its implemented incorrectly or anything but one fine day it struck me that there is a little difference in the way I used to implement hashtable in C/C++ and the way java Hashtable is "used".

Okay..without more theory I would say following,

1. Hashtable as Data structure we learned that we can group objects together based on some criteria and store it such so that we can get them back faster (fast lookup)

2. In C/C++ I implemented the hashtable as linked list of linked list way where vertical linked list holds the pointer to the other linked lists and I used the Hash function to determine which verticale bucket the input object will go upon calling put() method

3. In java Hashtable internally defintely implements the same concept BUT the way we use the Hashtable is more of "key, value" pair holder. NVList (Name Value Pair List).

4. Many times when I needed to have one "key" hold the data in form of list I would use one of the List object as "value". Here also we are still having "key,value" concept rather than one Key bucket holding reference to the Linked List of vlaues.

Due to this difference one day I questioned myself that "is not this confusing?" Of course it got cleared up after pondering a little bit more but this was just a thought...

To give example of this confusion is the question that,
"implement the hashtable in java for holding integer values where hash function is mod 10". Here if we use List it falls into 4th point's category BUT if we want to implement it like we do in C/C++ then you would probably understand what confusion I am trying to point to here...

Regards,
Maulin
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Originally posted by Maulin Vasavada:
Hi .... then you would probably understand what confusion I am trying to point to here...


I have not fully read your post several times to gaing detailed grasp of exactly what nuance(s - if any) you are examining, but one fundamental conceptual issue stands out to me.

You implement Hashtable as a List ? Did I hear you correctly ? Uh, this warrants discussion. Lets open with it is my understanding that all collections in Java are implemented as a Map. Also, there similarities that cross Map and Hashtable. Concepting the two, as well as implementing them raises design issues of duplicate elements, collisions and collision table lookup - quite a decent set of design criteria come up quickly, but none of them suggest implementing Hashtable as a List, in fact List is often written as a Hashtable ~ then sorted on retrieval to present the illusion of ordering.

Looks stupid, works great.


"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Nicholas

No. I am not suggesting implementing hashtable by List. All I am saying is if I take the way we did implement hashtable in C/C++ (using Linked List of Linked List) that differs from the the way we "use" hashtable in Java. In java we use mostly for Name, Value pairs storage. More like Properties.

I guess I am not able to acurately describe what I am thinking so we can leave this alone without getting people confused for no reason

Regards,
Maulin
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Originally posted by Maulin Vasavada:
Hi Nicholas
I guess I am not able to acurately describe what I am thinking so we can leave this alone without getting people confused for no reason

I have confused some people, not meaning to, and had several Grand Masters follow me until the post reached ten kilobytes of html returned from the script. I feel I understand your question in depth, and strongly suspect you have been insructed formally in a manner which is inconsistent with the underlying implementation such as in
It's likly not that Hashtable concept implemented in Java is distinguishable from with general hashtable concept, it is that one needs to address the concept of a Collection of items, how to store those items and so on. List is one way. Map is another, I have found that I overlook Set ... and that it is usually what I achieve by Map or Hashtable.

See: Knuth, Vol III
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
4. Many times when I needed to have one "key" hold the data in form of list I would use one of the List object as "value". Here also we are still having "key,value" concept rather than one Key bucket holding reference to the Linked List of vlaues.


I would have said the common understanding for Map (Hashtable, Hashmap, etc) to be key & value pairs. Your more flexible approach in C/C++ is not unsual, but it is a special case of value.

It's pretty common to have a hashmap contain values that are other complex objects. The "value is a list" design came up so often that it earned a name, multimap, and a number of implementations in Java and other languages.

Does it seem unnatural for the value to be another complex object? The key can be as complex as you like, too!
[ May 22, 2007: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hashtables in java might confuse the general hashtable understanding