How will you design a table datastructure for lookup?
I basically have to represent the following table
Country Activity Legal_Age
European Drink 18
European Drive 21
American Drink 21
American Drive 18
Here my Key is (Country & Activity) and the value is Legal_age.
I thought of using std::map to breakdown this problem (into individual maps) as follows.
national_Activity_age_map
European European_Activity_age_map
American American_Activity_age_map
European_Activity_age_map
Drink 18
Drive 21
American_Activity_age_map
Drink 21
Drive 18
But the problem here is, as the number of columns to the original table keeps growing, the number of maps to be added and maintained keeps growing.
Let’s say the US chooses to have seperate drinking ages for US-citizens and non-citizens. Then I will have to add new mappings and also modify existing mappings.
Is there a simple & a clean way to represent this data in a DataStructure which takes in a multiple factored Key and produce one value?
There are a few similar questions like below but nothing answers my specific problem.
What datastructure would you use to represent this format of data?
Update:
I can’t use Boost features at work since it has to be ported (or something like that). Is there a C++ (gcc 4.1.2) feature that I can use.
Try Boost Multi-Index.