Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Equal insert time for both row and column on a table model

 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul sorry how do you mean by the following?

mapping (row, column) -> cell number

What datatype is involved here?
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, sorry I'm not aware of a data structure that can stores all of the following:
- Integer to represent row number
- Integer to represent column number
- Array index, if that's what you mean

Can you give some links to this method?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!