最有效的方式来搜索字符串在另一个字符串数组 [英] The most efficient way to search for an array of strings in another string

查看:100
本文介绍了最有效的方式来搜索字符串在另一个字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的arrray字符串看起来是这样的:     字符串临时[] =新的String [200000]。

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

我还有一个字符串,姑且称之为bigtext。我需要做的是遍历临时的每个条目,检查,看看是否能进入在bigtext发现,然后做基于它的一些工作。所以,骨骼肌code看起来是这样的:

I have another String, let's call it bigtext. What I need to do is iterate through each entry of temp, checking to see if that entry is found in bigtext and then do some work based on it. So, the skeletal code looks something like this:

for (int x = 0; x < temp.length; x++) {
  if (bigtext.indexOf(temp[x]) > -1 {

  //do some stuff
  } else continue;
}

由于有在温度这么多的作品,有bigtext的多个实例,以及,我想这样做的最有效的方式。我想知道如果我所概括就是遍历该搜索是否有更好的方法来做到这一点的最有效的方式。

Because there are so many entries in temp and there are many instances of bigtext as well, I want to do this in the most efficient way. I am wondering if what I've outlined is the most efficient way to iterate through this search of if there are better ways to do this.

谢谢

艾略特

推荐答案

我认为你正在寻找类似的拉宾,卡普或<一href="http://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm">Aho–Corasick其目的是为了在平行于在文本大量子串的搜索。

I think you're looking for an algorithm like Rabin-Karp or Aho–Corasick which are designed to search in parallel for a large number of sub-strings in a text.

这篇关于最有效的方式来搜索字符串在另一个字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆