Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 大量可能性的最佳搜索技术_Algorithm_Search_Set - Fatal编程技术网

Algorithm 大量可能性的最佳搜索技术

Algorithm 大量可能性的最佳搜索技术,algorithm,search,set,Algorithm,Search,Set,我试图在文本文件中搜索大量可能性 例如,我想搜索包含唯一名称的文本文件。 现在,如果我找到了名称X,那么我想将X存储在另一个文件中 这里的问题是我有1000多个唯一的名字,我不想为每个唯一的名字做1000个搜索调用和if语句 在java/javascript/php中有更好的方法吗?您有一组名称,希望找到与另一组名称匹配的名称 Set<String> namesFromFile = readFile(filename); Set<String> namesToMatch

我试图在文本文件中搜索大量可能性

例如,我想搜索包含唯一名称的文本文件。 现在,如果我找到了名称X,那么我想将X存储在另一个文件中

这里的问题是我有1000多个唯一的名字,我不想为每个唯一的名字做1000个搜索调用和if语句


在java/javascript/php中有更好的方法吗?

您有一组名称,希望找到与另一组名称匹配的名称

Set<String> namesFromFile = readFile(filename);
Set<String> namesToMatch = readFile(matchingNames);
namesToMatch.retainAll(namedFromFile);
印刷品

The intersect of 100,000 and 10,000 elements has 5,000 and took 21.173 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 10.785 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 9.597 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 3.414 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.791 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.629 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.689 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.753 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.704 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.645 ms

它们是以某种方式分隔的吗?逗号,空格,新行?如果是这样,您可以获取内容,分解它,将其放入数组中,运行array_unique()并获得唯一名称列表。然后运行一些东西来迭代,并为每个文件创建新的文本文件。是你的朋友。不,他们更像是在字里行间。约翰和迈克要去某处。我需要找到“约翰”和“迈克”。然后用什么语言将它们存储在另一个文件中?你不是在用Java、PHP和JavaScript编写代码吗?请不要无意义地添加标签以引起更多的注意。是否可以知道匹配的名称?我的意思是,如果我有约翰,迈克,南希,只有约翰和迈克匹配,有可能知道吗?我只是想理解一下。如果这听起来很愚蠢,那么很抱歉。如果两个列表匹配正确,retainAll将返回true或false?也就是说,我可以在哪里找到匹配的名称?这将保存在namesToMatch中吗?我为一个10倍大的集合添加了一个基准,让您了解速度。根据Javadoc,它将第一个集合修改为“零售所有”第二个集合中的元素。
The intersect of 100,000 and 10,000 elements has 5,000 and took 21.173 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 10.785 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 9.597 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 3.414 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.791 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.629 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.689 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.753 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.704 ms
The intersect of 100,000 and 10,000 elements has 5,000 and took 2.645 ms