I am looking to store my data in a data structure which allows me to do the following efficiently:
I have 10 arrays of type 1 and 10 arrays of type 2 with 100 elements each. Each of these array store values of 100 variables. Accompanying these I have 20 arrays containing the corresponding variable IDs.
In total arrays of type 1 store values of 1000 variables and arrays of type 2 store different values of the same 1000 variables.
Now, I need to take a difference of the values of variables in arrays of type 1 from that of arrays of type 2. Let A be the one of the array of type 1. The problem is that variables in A would be spread 10 each across all 10 arrays of type 2.
A hash map would not be useful as I also need to iterate over the values in each array. Any ideas?
If you are intending to do such operations often you might want to construct and index at the program startup (the construction has
O(n^2)time complexity) once and then refer to it later.This would allow you to linearly go through arrays of type
Aand get the values from arrays of typeBin a constant time. You can also subtractBitems fromAin a similar fashion.Alternatively, you can go through the index items and subtract one item from another.