There is two string set (c++)
set<string> set1, set2;
I need to iterate set1 to check if any string in set1 is substring of string in set2.
Code below is my solution, is there any fast algorithm?
for(auto& str1 : set1) {
for(auto& str2: set2) {
if (strstr(str2.data(), str1.data()))
// do something
}
}
There are some restrictions
- this function is used in online RPC servers
- candidates of set2 and set1 may be too large to be loaded in memory entirely, so I can't build some index like trie or cache result.