Albert Schlef wrote:
> C. Dagnon wrote:
>> 4. And what's up with Ruby incorrectly naming their Map 'Hash'?
> [snip]
>> A 'Hash' would instead be a type of set.
> 
> What do you mean in that last sentence?

A set simply contains values while mathematically a hash is a process 
use to relate a value to a (hopefully advantageous) calculated value. 
As used here, referring to a type of collection, a hash is the same as a 
set: storing single, unrelated values.  The hash's benefit is being able 
to quickly check/retrieve individual items.  For each of them there is 
only one user-defined value involved per item in each collection. 
(Typically users don't know or care what the hash algorithm or hash 
values are thanks to encapsulation or other abstractions.)

Maps instead use one user-defined value to relate to a second 
user-defined value by a user-defined relationship, the mapping.  All 3 
parts are knowledge defined external to the Map.  The keys (and values) 
can be stored as a hash set or ordered list or whatever makes sense. 
Since the key-value relationship is user-defined you don't see generic 
Map collections internally using an algorithm to magically go from key 
to value: They have to concretely store the pairings so they know what 
they are.

Interesting, though, as after you got me thinking about it I started to 
wonder myself.  Initially Hash and Map seem so distinctly alien to each 
other that I can only hope the above proves clear enough.


Thank you for the question, and please let me know if I answered the 
wrong one!
-- 
Posted via http://www.ruby-forum.com/.