From: Mathieu Bouchard Date: 2001-07-16T11:27:33+09:00 Subject: [ruby-talk:17898] Re: Sets, Hashes On Sat, 14 Jul 2001, Hal E. Fulton wrote: > For example, when you iterate over a set (at least, the way I was taught > in discrete math), you don't get any fixed ordering. Two possibilities > might be just to document this and let the user hang himself; or we > might actually randomize the order so that it was actually different > each time. Let the user hang himself by providing him with over half of the semantics of the Hash class, which iterates over a *set* of rows in a usually chaotic and reproducible order but which is not guaranteed to be so. Later provide both of Set and Hash with a randomizer if you wish to. > Another question is: Might there be times when it was difficult to tell > whether an object being added was a duplicate? What kind of equality > test do we use, considering that a set might contain completely > arbitrary objects? Use the semantics Hash uses for its keys in #eql? and #hash. On Sun, 15 Jul 2001, HarryO wrote: > I definitely think Set is a worthwhile type to have separately to Array. > It could probably be implemented by wrapping an Array, in order to > minimise the amount of rewriting, but an efficient implementation would > probably do it a better way. What you really want is wrapping Hash. On Sun, 15 Jul 2001, Shan-leung Maverick WOO wrote: > For example, when I am enumerating a container, most of the time I don't > really don't care if it is a Hash, an Array, or a (future) Dictionary (if it > exists). Ruby's Hash is SmallTalk-style Dictionary; MetaRuby's HashP, HollowHash (formerly HashMixin) correspond to Java's idea of Dictionary (abstract class) even though it follows Ruby's Hash api. matju