What type of data structure (or data structures?) could be used to store a pivot table of two dimensions where the data can be accessed? For example, let's take the following, copied from Excel:
If the data was all in a one-dimensional hierarchy -- that is, it went Group > Product > Year > Value, we could do something along the lines of:
{
"Electronics": {
"(all)": {
"Year": {
"2018": 2,
"2019": 1,
"Grand Total": 3
}
},
"Computer": {
"Year": {
"2018": 1,
"2019": 0,
"Grand Total": 1
}
},
"Phone": {
"Year": {
"2018": 1,
"2019": 1,
"Grand Total": 2
}
}
}
}
And then I could access the Value at Electronics > Computer > 2018 by doing:
obj["Electronics"]['Computer']['Year']
// {2018: 1, 2019: 0, Grand Total: 1}
obj["Electronics"]['Computer']['Year'][2018]
// 1
But I can't think of how this would be put into a two-dimensional data-structure outside of a 2D multi-dimensional array that really wouldn't have any usage other than being able to retrieve a value at a certain position (and I'd need to store tons of metadata in order to know what is stored at which placement).
What would be a suitable data structure for this? I've tagged this Java, C, C++ -- any language is fine, I'm more interested in the actual data structure.