Recently, I met two use cases
efficiently query whether a given string
wordis a substring of some elements of a collection of strings.efficiently query whether some elements of a collection of strings are substring of a given string
word.
class StringSet {
void add(String s);
void contains(String s);
void remove(String s);
List<String> getAllSubstringsOfGivenWord(String s);
List<String> getAllStringsContainsGivenWord(String s);
}
For example, the collection of String is {"abc", "dab", "bcd"}, then getAllStringsContainsGivenWord("ab") --> ["abc", "dab"], getAllSubstringsOfGivenWord("dabc") --> ["abc", "dab"]
Which kind of data structure suits for these kinds of use cases?