in reply to Re: What defines the choice of a Hash or an Array?
in thread What defines the choice of a Hash or an Array?
I'm not sure why you bring up the issue of storing array references in hashes versus arrays. I'm also not sure why speed is a consideration. Arrays are useful where you need ordered access, where you might use a data structure such as a stack, a queue, a dequeue, or access to a list of items by sequential indexes. Hashes are useful when you need keyed access to a list of items where near-constant access time is more important than preserving insertion order.
That dubiousity aside, I think the rest of your post is confusing misinformation.
I think that the name of the perl data types: ARRAY and HASH are confusing this issue. It is important not to confuse these data types with the data structures with simular names.
No, this is wrong.
The Perl data type has the name ARRAY because it is an array. The Perl data type has the name HASH because it is a hash.
Both perl data types can be used to create arrays:$ARRAY->[1][2] = 'bob'; $HASH->{1}{2} = 'bob';
This is half wrong. The first is an array because it's an array. The second is not an array because it's a hash. Try iterating through the indexes of the hash, for example. Try using a non-integer as the index of an array. Try using a huge integer as the index of an array.
Sure, if you provide a really degenerate, simplified definition of what an array is, you can emulate it with a hash, but that doesn't make it an array.
If you your arrays are more more 1 dimentional then the ARRAY data type really looses all of its advantage over the HASH data type, as it can no longer be used directly as a list.
I don't know what this means, but unless you're talking about the need to dereference nested arrays (which you also have to do with nested hashes), I think it's wrong too.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: What defines the choice of a Hash or an Array?
by Anonymous Monk on Apr 01, 2005 at 08:12 UTC |