Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • They really are different. If nothing else, the two terms are meaningful at different levels of abstraction.

    An associative array is a source language level concept. It means an array which is indexed by arbitrary, unordered values, typically (but not necessarily) strings.

    A hash table is a data structure in which keys are crunched through a hashing function in order to get the actual index used in the table. This is to handle both the unordered-ness and the sparseness of keys.

    Associative arrays need no
    • An associative array is a source language level concept. It means an array which is indexed by arbitrary, unordered values, typically (but not necessarily) strings.
      A hash table is a data structure in which keys are crunched through a hashing function in order to get the actual index used in the table. This is to handle both the unordered-ness and the sparseness of keys.

      Correct me if I'm wrong, but to add to this I believe important distinction that a hash value is a number created by a function which effectively acts as a signature for the object (eg string). And hash values may collide - ie two or more different objects may happen to generate the same hash value for some hashing function. If implemented a store by generating 8 bit hash values for strings and used that 8 bit hash value as the index in an array, then you're likely to start finding that things collide (ie two different strings want to be in the same array position). Notice that a hashing function is a one way trip - given an object you can calculate the hash value, but given the has value, you can't get an object back

      Whereas an associative array is an abstract concept, which doesn't tell you how it's implemented, merely that it will fulfil some properties. One of which is that you won't get different objects trying to be stored in the same place, another is that you can get your objects back out.

      People keep talking about hash methods for parrot, and I get frustrated because I don't think that they really just mean methods for calculating hash values. I think they are usually meaning the whole whack about finding unique ways to serialise objects so that distinct objects have 0 chance of collisions, and so that they can get the objects back