'How to get entries with partial keys (in any order) in map c++?
Assume below are the entries in a c++ map with key as some structure. 0, 1 in the below map need not necessarily be only integers/string. It can also be any user-defined data type.
---------------------
Key | Value
---------------------
(0, 0, 0, 0) | a
(0, 0, 0, 1) | b
(0, 1, 0, 1) | c
(0, 1, 1, 0) | d
....
Below are different queries to look-up in map:
1) (0, 0, 0, 1) -> b
2) (0, *, *, *) -> [a, b, c, d]
3) (0, 1, *, *) -> [c, d]
4) (*, 1, 1, 0) -> [d]
5) (*, *, 0, 1) -> [b, c]
6) (*, 1, 1, *) -> [d]
7) (*, 0, *, 1) -> [b]
The idea is to have '*' anywhere in the key, and do the look-up efficiently without iterating over all the entries.
'*' indicates wild card (it can be anything).
Can anyone suggest on how to solve this problem ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
