其中数据结构,我应该使用搜索从CSV字符串? [英] Which data structure should I use to search a string from CSV?

查看:101
本文介绍了其中数据结构,我应该使用搜索从CSV字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个columns-名称及放近20万行的csv文件;工作。然后,用户输入一个名字,说USER_NAME,我有搜索整个CSV查找包含模式USER_NAME并最终打印输出到屏幕上的名字。我已经实现这个使用ArrayList的在Java中,我把整个名字从CSV到ArrayList和搜索,然后在它的模式。但在这种情况下,用于搜索的总的时间复杂性为O(n)。有没有在Java中的任何其他数据strucure,我可以用它来在O(LOGN)或东西比ArrayList的更有效的进行搜索?我无法通过的方式使用任何数据库的方法。此外,如果存在这样我可以用它来实现我的目标的任何其他语言的一个很好的数据结构,那么它好心建议我?

I have a csv file with nearly 200000 rows containing two columns- name & job. The user then inputs a name, say user_name, and I have to search the entire csv to find the names that contain the pattern user_name and finally print the output to screen. I have implemented this using ArrayList in Java where I put the entire names from csv to ArrayList and then searched for the pattern in it. But in that case the overall time complexity for searching is O(n). Is there any other data strucure in Java that I can use to perform the searching in o(logn) or something more efficient than ArrayList? I can't use any database approach by the way. Also if there is a good data structure in any other language that I can use to accomplish my goal, then kindly suggest it to me?

编辑 - 输出应该是在包含该模式USER_NAME作为最后一部分CSV的名字。例如:如果我输入儿子,那么它​​应该返回禅师,等等。现在我迄今所做的阅读CSV的名字列到一个字符串ArrayList中,然后读取ArrayList中的每个元素,并使用常规的前pression(爪哇模式的匹配),看看是否该元素具有USER_NAME作为最后部分。如果是,那么打印出来。如果我实现这个在多线程环境中,它会增加我的程序的可伸缩性和性能?

Edit- The output should be the names in the csv that contains the pattern user_name as the last part. Eg: If my input is "son", then it should return "jackson",etc. Now what I have done so far is read the name column of csv to a string ArrayList, then read each element of the ArrayList and using the regular expression (pattern-matcher of Java) to see if the element has the user_name as the last part. If yes, then print it. If I implement this in a multi-threaded environment, will it increase the scalability and performance of my program?

推荐答案

您可以使用:


  • TreeMap的,将垃圾分类红黑树,<​​/ li>
  • TreeMap, it is sorted red-black tree,

这篇关于其中数据结构,我应该使用搜索从CSV字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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