views:

174

answers:

3

I need a Java implementation of table-like data structure where I could dynamically insert or delete rows and columns. I need to get data from any row or column very fast and with no overhead in selecting row over column or vice versa.

Does anyone know libraries where such data structure is already implemented?

A: 

Perhaps JQL or HSQL DB

questzen
JQL is just a syntactic sugar for querying existing data structures. And I really doubt that full-blown SQL database is a solution in my case (I need to select rows/columns from that table thousands times per seconds).
Alexander Temerev
HSQLDB is _very_ lightweight, I think it's worth at least to run a performance test to see if it answers your requirements.
Eli Acherkan
+3  A: 

You might be able to use the DefaultTableModel. It was intended to be used with a JTable, but there is no reason it can't be used alone. You would need to add methods to retrieve the data for a full row or column.

camickr
This is creative, I like it.
Alexander Temerev
My only concern is that it uses Vectors for the storage which will add unnecessary synchronization overhead if you really are accessing rows and columns thousands of times per second. The approach is valid though, just maintain a List of Lists.
Kevin
Its parent,`AbstractTableModel`, makes it easy to use your own data structure. You'll need to code your own updates, but the notification mechanism is in place. http://java.sun.com/javase/6/docs/api/javax/swing/table/AbstractTableModel.html
trashgod
+1  A: 

If the performance is critical, you can use a 2D-array, and implement a reallocation algorithm (e.g. doubling) so that it can grow.

Eli Acherkan
Though about it. Will do that if the first proposed solution's performance proves not to be enough.
Alexander Temerev