From: Austin Ziegler Date: 2003-11-19T16:02:34+09:00 Subject: Re: Multi-dimensioned sparse array ? On Wed, 19 Nov 2003 14:21:19 +0900, Charles Hixson wrote: > Does anyone have an implementation of a multi-dimensioned sparse > array? What about using hashes? msa = Hash.new { |h, k| h[k] = Hash.new } If you just use Numeric keys, there's little difference for your needs. You can subclass Hash to make it act a bit more like an Array under certain circumstances (e.g., #each would return values in key-order instead of a key-value pair; you could also do an ordered hash per [ruby-talk:20551] to potentially save sort times). For multi-dimensional auto-vivifying, you could do: hash_maker = proc { |h, k| h[k] = Hash.new(&hash_maker) } msa = Hash.new(&hash_maker) http://www.rubygarden.org/ruby?HashOfHashes -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2003.11.19 * 01.34.12