Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^5: What makes an array sorted and a hash unsorted?

by Roy Johnson (Monsignor)
on Jun 01, 2009 at 18:07 UTC ( [id://767343]=note: print w/replies, xml ) Need Help??


in reply to Re^4: What makes an array sorted and a hash unsorted?
in thread What makes an array sorted and a hash unsorted?

"Hashes are not sorted the way you think they are sorted" would be correct today as well as with your change. However, it is also (theoretically) possible to implement hashes that retain an order unrelated to their keys. If that were implemented, it would "help", and so the problem is that hashes are unsorted -- in that way.

I still contend that it is the language that makes them unsorted. It is not merely how we use them. Order has to be imposed externally on the data. There is no intrinsic ordering.


Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^6: What makes an array sorted and a hash unsorted?
by ikegami (Patriarch) on Jun 01, 2009 at 18:12 UTC

    So hashes aren't ordered because the following doesn't work?

    $h{foo} = 'a'; $h{bar} = 'b'; $h{baz} = 'c'; is(join(' ', values(%h)), "a b c");

    I guess arrays aren't ordered either, then.

    $a[2] = 'a'; $a[0] = 'b'; $a[1] = 'c'; is("@a", "a b c");

    Order has to be imposed externally on the data in the case of arrays too. It's just there's a convenient way of doing that when the keyspace isn't sparse (namely, the range operator).

      You're trying too hard. You're now saying that there must be exactly one kind of ordering that constitutes ordering, and nothing else can be considered ordered. Or that every ordering must be implemented for a thing to be considered ordered. I'm not sure which you're contending; they're both pretty stupid notions, which is why it surprises me to see you pushing it as a serious argument.

      Order has to be imposed externally on the data in the case of arrays too.
      No, order is intrinsic to arrays. Not every possible order, but the one that is intrinsic. Any other ordering would have to be imposed. Arrays have one intrinsic ordering. Hashes have zero intrinsic orderings.


      Caution: Contents may have been coded under pressure.

        I'm not sure which you're contending

        I'm saying there's no difference between hash and arrays expect in the order they choose to return their values. A hash could return its values in the same order as an array. And if it did, people would still ask how to sort hashes.

        With which of these premises do you disagree?

        Arrays have one intrinsic ordering. Hashes have zero intrinsic orderings.

        So? Even if hashes had an intrinsic ordering, the same problems faced today would still exist. There's more to it than that, or the answer to the posts we see isn't "hashes aren't ordered".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://767343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-29 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found