From: Christoph Rippel Date: 2001-02-20T08:40:02+09:00 Subject: [ruby-talk:11138] Re: Summary: RCR #U002 - proper new name fo r indexes "Dave Thomas" wrote in message news:m2d7cemh2r.fsf@zip.local.thomases.com... > David Alan Black writes: > > > In spite of being an advocate of having two different names, I do > > agree that conceptually an array is essentially a hash on positive > > integers. (See for example [ruby-talk:6611] and [ruby-talk:6663].) > > In fact, looking at arrays and hashes that way makes me wonder about > > what *exactly* is common to them, and what implications that has. I > > keep thinking of a phantom module called "Hashable", and wishing it > > existed.... > > I'm not sure I agree that they are essentially the same. For example: > > a = [] > a[0] = 0 > a[10] = 10 > p a #=> [0, nil, nil, nil, nil, nil, nil, nil, nil, nil, 10] > > b = {} > b[0] = 0 > b[10] = 10 > p b #=> {0=>0, 10=>10} > > An array is a vector, while a hash is an indexed collection. Arrays > have key-ordering, while hashes are unordered. On the other hand you find that p a[9] # => nil p b[9] # => nil the only difference is that a.length # => 10 and b.keys.length # => 2 but this is a (questionable?) artifact of Ruby's Array implementation I think David's point was that vectors are functionally equivalent to Hashes with key's in Fixnum (apart from this obscure artifact). > However, I _would_ agree that both arrays and hashes might be > derivable from some underlying collection class. Agreed Christoph