From: Kedar Mhaswade Date: 2011-01-11T05:27:36+09:00 Subject: Re: Nooby question : multidimensional arrays. Robert Klemme wrote in post #973678: > On Mon, Jan 10, 2011 at 4:14 PM, Kedar Mhaswade > wrote: >>> If you need that you could do something like >>> https://gist.github.com/772827 > >> Interesting. Thanks, Robert. >> But using hash internally to represent arrays is slightly >> counterintuitive. > > Well, you don't see it from the outside. For users of the class it > doesn't really matter how it internally works (unless they hit some > limitations). I meant for a programmer to implement it. And yes, it is a damn good idea. > >> But I agree, it will work well for "sparse" >> multi-dimensional arrays. > > Exactly that was the use case I had in mind. > >> I realize that I could do something similar >> and still retain the one-dimensional flattening, in my implementation. > > How exactly do you want to do that? Grrr. I was not thinking enough. I could make the current implementation better in that I can lazily expand the array which will fill the intervening elements with nil's but yeah, it's nowhere near the fast lookup of hashtables. > >> And yes, expanding it to do non-cube entities is on my list. > > :-) Actually "cube" is just a special case of the more general one. > I'd rather implement the special case and add a custom constructor for > the cube case: > > https://gist.github.com/772827 > > Cheers > > robert -- Posted via http://www.ruby-forum.com/.