Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 26951
83
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 26951
83
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic