[英]Searching through a list of 100,000 elements as fast as possible in C#
I will soon have the need to repeatedly search through a list (about every 15s) of about 100,000 elements as fast as possible using C# looking for elements that have specific values. 我很快将需要使用C#查找具有特定值的元素,以便尽可能快地反复搜索大约100,000个元素的列表(大约每15s)。 Would searching a List with Linq for elements (where 3-4 fields have specific values) be faster than using for example, an in-memory SQLite database? 使用Linq在List中搜索元素(其中3-4个字段具有特定值)会比使用内存中的SQLite数据库更快吗? Is there a better option available? 有更好的选择吗?
I wouldn't mind recreating the database upon every program execution, so reading data in from a CSV file would be acceptable. 我不介意在每次执行程序时都重新创建数据库,因此从CSV文件读取数据是可以接受的。
The dataset will be a window from a stream of data, subsequently, the list will gradually change, with one record being removed from the start of the list, and one more added to the end every 15s. 数据集将是数据流中的一个窗口,随后,列表将逐渐更改,从列表的开头删除一条记录,然后每隔15秒将另一条记录添加到末尾。
What options do I have? 我有什么选择?
You can use a helper library named IndexedList, you can download it from http://indexedlist.codeplex.com/ With this library you can add indexes on any field(s) of your object then perform fast searches in your list. 您可以使用名为IndexedList的帮助程序库,也可以从http://indexedlist.codeplex.com/下载该程序库。使用该库,您可以在对象的任何字段上添加索引,然后在列表中执行快速搜索。 Default index implementation uses Dictionary for storing index data, you can change it too. 默认索引实现使用字典来存储索引数据,您也可以更改它。 I have created this library for my own projects then i published that as an open source project newly. 我已经为自己的项目创建了这个库,然后我将其作为一个开源项目新发布了。 I will be happy to hear your feedback about this library. 我很高兴听到您对这个图书馆的反馈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.