Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re^5: What makes an array sorted and a hash unsorted?by herveus (Prior) |
on Jun 03, 2009 at 13:31 UTC ( [id://768007]=note: print w/replies, xml ) | Need Help?? |
Howdy!
You appear to be conflating being ordered with being sorted and searching with simple access. Arrays are ordered. The elements have a defined order. Orderedness and sortedness are not the same thing. One speaks to the intrinsic sequencing of the elements of a collection (orderedness) while the other speaks to an externally imposed sequencing of the elements of a collection (sortedness). Searching for an element is different from accessing an element. In the first case, you don't know which element is the target, so you have to find it. Accessing a specific element means you have the index of the item already. For a hash, the index is a string; for an array, the index is an integer. You cannot speak generally of the intrinsic sequence of the elements of a hash. It is not a fixed quantity. Adding or removing elements can change the sequence in ways that are not readily predictable. Iterating over the elements first involves collecting the set of keys. That act turns them into a list which has an intrinsic order, but it's no longer a hash or a set. The set of keys has become an ordered n-tuple (where n is the number of keys), but it's no longer a set.
yours, Michael
In Section
Meditations
|
|