Reputation: 87
I have a table where the entries are something like this
Row - Column1 - Column2 - Column3 Column4
1 0X0A 1 2 A
2 0X0B 2 2 B
3 0x0C 3 2 C
Now i want to use map in such that i can use column 1 or Column 2 as the key to get the row. What kind of map i should use to achieve this?
(Note- Table is just for explanation and not the exact requirement) I thought of using multimap, but that is not going to solve the prob
Upvotes: 4
Views: 3007
Reputation: 62519
Define a class similar to pair
with a custom comparator that indicates equality if either the first member or the second member match, but not necessarily both. You could then use that class as your key type. You would probably need a particular value for each member that will never be used in your data, to use as default values in your constructor, to avoid keys where only the first member has been initialized occasionally matching on the second member due to leftover data.
Upvotes: 2
Reputation: 28802
You could use one map to map from column 1 to the row and another to map from column 2 to the row. Repeat for as many columns as needed
Upvotes: 0