Difference between HashTable, HashMap, HashSet & Hash what else you name it

In CS101 we've learnt HashTable and it is the same paradigm with that python dictionary, right? if yes move on.

So my question is simple:

  1. Seriously, there are how many Kind of Hash in this Hash Family?
  2. Hmm. actually I stumble upon this term after surfing around the web
    to find out more info on hash table. But struggle to understand the
    difference as their explanation not quite newbie-friendly. So
    what is the difference between HashTable vs HashMap vs HashSet vs
    (you may add it here any kind from Hash Family)?

Thanks :)

asked 04 Apr '12, 02:41

Yulianto's gravatar image

Yulianto
1.4k31564
accept rate: 52%

closed 04 Apr '12, 10:47


One Answer:

First of all, hash<anything> means that you are implementing <anything> using a hash function of some kind that will give you a bucket index to find whatever you are looking for efficiently.

That being said, hashtable is a table implemented with a hash function, hashmap is a map implemented this way, and likewise for hashset.

A table, a map, and a set are just different data structures to store things.

In general, a table is a collection of "records". You may think of a table in python as a list of lists (of lists,...). For example: [[studentname, phonenumber, birthdate, [friend1,friend2,...]...],...].

A map is collection of "key"-"value" pairs. Essentially we have a collection of mappings from keys to values, e.g. keywords to urls. A hashmap then is an efficient way to add/lookup keys and their corresponding values. I'm not certain, but I think the dictionary we used is a hashmap, not so much a hashtable (though similar).

A set is just a collection of elements. In C++, a set would have to be a collection of elements of the same "type", such as integers, or strings, but not a mix. I'm not quite so sure there is a distinction for sets in Python, since we can just use lists to hold any type of element we want.

Not aware of any other types of hash.
Hope this helps!

link

answered 04 Apr '12, 03:32

Stanley%20Xu's gravatar image

Stanley Xu
1789

edited 04 Apr '12, 03:32

To add to the confusion, different languages call their own fancy name for hash maps, some call it dictionaries (wonder which one..), associative arrays, maps, hashmaps etc. Of course this is probably because they all have slightly different implementations, but conceptually they are same.

(04 Apr '12, 03:43) fazal fazal's gravatar image

Sets are unordered collections with no respect for duplicates. This is true for both Python and C++ (in C++, you could use an std::vector just as well as you could use a list in Python).

(04 Apr '12, 03:44) Anton Golov ♦ Anton%20Golov's gravatar image

Good point about sets jesyspa. Except in C++ a vector is restricted to holding elements of the same data type, whereas a list can hold elements of any type!

(04 Apr '12, 03:56) Stanley Xu Stanley%20Xu's gravatar image

The same restriction applies to std::set in C++.

(04 Apr '12, 03:58) Anton Golov ♦ Anton%20Golov's gravatar image
Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15,312
×33
×1
×1
×1

Asked: 04 Apr '12, 02:41

Seen: 2,206 times

Last updated: 04 Apr '12, 10:47