I need to implement an efficient excel-like app.
I’m looking for a data structure that will:
- Store the data in an efficient manner (for example – I don’t want
to pre-allocate memory for unused cells). - Allow efficient update when the user changes a formula in one of the cells
Any ideas?
Thanks,
Li
In this case, you’re looking for an online dictionary structure. This is a category of structures which allow you to associate one morsel of data (in this case, the coordinates that represent the cell) with another (in this case, the cell contents or formula). The “online” adjective means dictionary entries can be added, removed, or changed in real time.
There’s many such structures. To name some more common ones: hash tables, binary trees, skip lists, linked lists, and even lists in arrays.
Of course, some of these are more efficient than others (depending on implementation and the number of entries). Typically I use hash tables for this sort of problem.
However, if you need to do range querying “modify all of the cells in this range”, you may be better off with a binary tree or a more complicated spatial structure — but not likely given the simple requirements of the problem.