Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: What makes an array sorted and a hash unsorted?by gwadej (Chaplain) |
on Jun 01, 2009 at 20:39 UTC ( [id://767374]=note: print w/replies, xml ) | Need Help?? |
I would not use the term sorted, I would use the term ordered. This distinction is perhaps more obvious when you look at another way to map a string to a value. The two approaches I'm familiar with are binary trees and hash tables. In the case of a binary tree, the items are ordered because the structure of the tree imposes an intrinsic order on the data. Hashes, on the other hand, are intrinsically not ordered internally. In fact, this feature is what allows for (relatively) inexpensive insertion and deletion. (Two items with keys very close to each other are likely to end up in different areas of the hash table.) As you said, the interface we see for the hash could be changed to return the data in an ordered fashion, but the data structure is still intrinsically unordered.
G. Wade
In Section
Meditations
|
|