From: Geert Fannes Date: 2006-03-14T03:53:56+09:00 Subject: Re: how to introduce reference objects into ruby ------_=_NextPart_001_01C646CF.713A3394 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable >I see your conundrum. However I think it should be possible to do what = you >want. If you maintain only the list of columns I think you can still = make it >work. > > > class MatrixRow > def initialize(columns, row_number) > @columns =3D columns > @row_number =3D row_number > end > def [](index) > @columns[row_number][index] > end > def []=3D(index, value) > @columns[row_number][index] =3D value > end > end > >class SparseMatrix > def initialize() > @columns=3DHash.new{|hash,key|hash[key]=3DHash.new} > end > def []=3D(i,j,value) > @columns[j][i]=3Dvalue > end > def getRow(i) > return MatrixRow.new(@colums, i) > end > def getCol(j) > return @columns[j] > end >end The problem with this is you don't know the valid elements in row "i": = implementing a #each method for MatrixRow will be problematic and = require you to go over ALL @columns, which takes way too long (@columns = has length 100000000, while row(i) will in general have only about 30 = elements. iterating through all 100M columns is too time consuming) Greetings, Geert. ------_=_NextPart_001_01C646CF.713A3394--