Thanks for references and detailed review. I will go over them to
understand them better. Just to reiterate, my implementation is pretty
rudimentary at this point and more importantly, it caters for the cases
where the number of elements in every dimension is assumed to be the
same (IOW, you can’t simply represent a 2x3 matrix is it).
Interesting. Thanks, Robert.
But using hash internally to represent arrays is slightly
counterintuitive. But I agree, it will work well for “sparse”
multi-dimensional arrays. I realize that I could do something similar
and still retain the one-dimensional flattening, in my implementation.
And yes, expanding it to do non-cube entities is on my list.
I simply started with flattening out the elements into a one-dimensional
array internally (which is quite obvious). I am not sure about its
applications yet. Also, dc[3] does not make sense for this
implementation, unless the DataCube itself is one-dimensional (in which
case it just degenerates to normal array).
So, if you have p dimensions, then the array has to be accessed (or
indexed) using an index like: [x, y, z, …] where the length of this
array itself is p.
That said, I haven’t yet considering “expanding the array” dynamically.
It’s like, you fix the # and size of dimensions upfront and freeze them.
I will address that officially, as you suggest.
I will admit, I haven’t checked the current literature of Data Cube when
implementing it. Maybe I should do that.
My modest expectation was that to address a point in multidimensional
space A[d1,d2,d3 … dn] was a more natural notation than
A[d1][d2][d3]…[dn], because the former is how we would represent it on
paper. And Ruby’s flexibility allowed me to do just that!
Thanks for references and detailed review. I will go over them to
understand them better. Just to reiterate, my implementation is pretty
rudimentary at this point and more importantly, it caters for the cases
where the number of elements in every dimension is assumed to be the
same (IOW, you can’t simply represent a 2x3 matrix is it).
Yes, you need 1.9ish Ruby for this to work. Reason is that 1.9 has
extended pattern matching. With 1.8 you need to do it yourself:
09:14:49 ~$ irb
Ruby version 1.8.7
irb(main):001:0> class X
irb(main):002:1> def []=(*a)
irb(main):003:2> v = a.pop
irb(main):004:2> p a, v
irb(main):005:2> end
irb(main):006:1> end
=> nil
irb(main):007:0> X.new[1,2,3]=4
[1, 2, 3]
4
=> 4
irb(main):008:0>
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:
Thanks for references and detailed review. I will go over them to
understand them better. Just to reiterate, my implementation is pretty
rudimentary at this point and more importantly, it caters for the cases
where the number of elements in every dimension is assumed to be the
same (IOW, you can’t simply represent a 2x3 matrix is it).
-Kedar
Kadar,
I was looking through my computers ruby packages and found one: