I have data structured in a table form
+------+------+------+------+
| | Col1 | Col2 | Col3 |
+------+------+------+------+
| Row1 | 1 | 2 | 3 |
| Row2 | 5 | 5 | 6 |
| Row3 | 9 | 2 | 7 |
+------+------+------+------+
I'm looking for a data structure that allows the following:
- Fast Iteration of column and rows (get the values for the column or the rows. (It should not be more expensive to iterate in one direction than in the other)
- Fast adding and removing of entire rows and columns (again both operations should be equally fast and should be at most O(n) )
- Order based on insertion order and reorderable. Order would be calculated with some comparators and is usually depended on the data in the row or column, but not on any names or such
- Store data other than numbers (We have mixed data, but I plan to use a container class for the actual data anyways)
Additionally rows and columns will have metadata (name, color and stuff like that). All these operations happen often in our system. Currently we store the data row based and the columns have no reference to the data related to them. This makes deleting a column or iterating over its data very tedious.
The first thing that sprang to my mind is the Guava Table
but that is not ordered and I'm not sure if it is easy to delete an entire row or column, although clearing the row or column map might do it.
Arrays as backing storage will not work because of adding and removing required. (Although I could predict how large the table will be and create new tables for the removing, but I don't like that solution, even if it could be hidden from the user)
I would be grateful for any ideas on how to implement such a data structure.
To clarify, I don't need a finished library that does this, but I'm looking for a data structure that would allow me do create this. I already know that I will be storing row and column meta-data in separate lists for example