D
Duncan M Gunn
Hi,
I need to store the following matrix of values:
T U V
A 2 1 1
B 2 - -
C - - 2
Where (-) is an empty cell.
The obvious solution is to store it as a 2D array, but I would like to store
this as efficiently as possible.
For example, the Matrix object need only store the cells that have a value,
if asked for a cell which is not assigned it can return a default empty
value.
I would also prefer to be able to access it by using only one index, e.g. if
only the y value is known then return a list of cells with that y value.
This could be achieved using a 1D array, where a given cell could be
accessed by multiplying the given x or y value by the respective number of
columns or rows. However, it would still require an array of x * y
elements, even when half of these elements are not required. I presume that
a completely empty x * y array of MyObject would take up x * y *
SizeOf(MyObject) space.
Does anyone know of an efficient data structure for a matrix?
Thanks,
Duncan
I need to store the following matrix of values:
T U V
A 2 1 1
B 2 - -
C - - 2
Where (-) is an empty cell.
The obvious solution is to store it as a 2D array, but I would like to store
this as efficiently as possible.
For example, the Matrix object need only store the cells that have a value,
if asked for a cell which is not assigned it can return a default empty
value.
I would also prefer to be able to access it by using only one index, e.g. if
only the y value is known then return a list of cells with that y value.
This could be achieved using a 1D array, where a given cell could be
accessed by multiplying the given x or y value by the respective number of
columns or rows. However, it would still require an array of x * y
elements, even when half of these elements are not required. I presume that
a completely empty x * y array of MyObject would take up x * y *
SizeOf(MyObject) space.
Does anyone know of an efficient data structure for a matrix?
Thanks,
Duncan