Pit captain:
Sven S. schrieb:
And I am 100% in favour of a order-preserving hash in the Ruby core.
snip
Sven, regarding the “HistoryHash” part of your post:In order to replace the standard Hash with a “better” Hash, there should
be a clear agreement on its desired behaviour. I don’t think this
agreement has been achieved yet. What should be the result of the
following code?
snip
I’ve not been following this post attentively…
My vote is against the proposal (to add semantics to Hash)- for what
it’s worth
I am very much in favour of the Hash remaining a Hash. It’s an extremely
useful datatype, and it’s clear what it does and doesn’t do.
Personally, I would very much like to see an ordered container in the
standard distribution. It would behave like the c++ stl’s map or set. (I
think these are commonly implemented on top of a b-tree, but other data
types are possible, I believe.)
Containers like this let you:
- iterate through entities in an ordered way.
- have log(n) insert time
- have log(n) search time
- let you to query for a close match (not necessarily an exact hit).
A Hash that also remembers insertion order seems like it could be
useful, although I don’t think I’ve needed one (while I have wanted the
container described above). I definitely don’t think such an order
preserving hash should replace what is in the standard though. In the
same way I wouldn’t want to add semantics to Array or Set.
The pragmatic approach (and what I imagine will happen) is that if
someone wants these, they should write them. If they’re then widely
used, they should go in to the standard distribution.
Cheers,
Benjohn