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?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: What makes an array sorted and a hash unsorted?
by JavaFan (Canon) on Jun 03, 2009 at 15:18 UTC | |
by herveus (Prior) on Jun 03, 2009 at 18:33 UTC | |
by JavaFan (Canon) on Jun 03, 2009 at 20:31 UTC | |
|
Re^6: What makes an array sorted and a hash unsorted?
by JavaFan (Canon) on Jun 03, 2009 at 14:00 UTC | |
by herveus (Prior) on Jun 03, 2009 at 14:16 UTC |