Hi, am curious if there's a way to build a table object (ie rows x columns) that gives you the same performance when inserting either a row or a column. In other words, the time it takes to insert a row should be the same as the time it takes to insert a column.
The only way I can see myself implementing this is to use either of the following:
Option 1: An array of columns, where each column is an array of rows.
Option 2: An array of rows, where each row is an array of columns.
Here I'm using the word "array" but it can be a vector, or list.
Option 1 gives faster time to insert a new column than to insert a new row.
Option 2 gives faster time to insert a new row than to insert a new column.
I have searched all over the web looking but still comes to the same conclusion above. Is there really no way to build a table that offers you equal insert speed of either row or column?
Just off the top of my head, you could use an array of cells along with a mapping (row, column) -> cell number. Then adding a row would involve copying the whole thing to a larger array (with a different mapping) and adding a column would also involve copying the whole thing to a larger array (with another different mapping).
The row number is an integer, and so is the column number. There's a pretty straight-forward method which maps a row number and column number into the cells of an array which has R*C elements, where R is the number of rows and C is the number of columns.