The most efficient way to search for an array of strings in another string

后端 未结 8 2320
礼貌的吻别
礼貌的吻别 2021-02-12 15:12

I have a large arrray of strings that looks something like this: String temp[] = new String[200000].

I have another String, let\'s call it bigtext. What I ne

8条回答
  •  醉酒成梦
    2021-02-12 16:00

    I'm afraid it's not efficient at all in any case!

    To pick the right algorithm, you need to provide some answers:

    1. What can be computed off-line? That is, is bigText known in advance? I guess temp is not, from its name.
    2. Are you actually searching for words? If so, index them. Bloom filter can help, too.
    3. If you need a bit of fuzziness, may stem or soundex can do the job?

    Sticking to strict inclusion test, you might build a trie from your temp array. It would prevent searching the same sub-string several times.

提交回复
热议问题