从内存数据集中过滤和查找
我的内存中有几个中等大小的数据集,我需要能够快速过滤和查找信息。数据集足够小,我不想每次需要一个条目时都访问数据库,但又足够大,我确实需要以某种方式索引数据。
目前,我正在使用 POCO 对象和一个或多个字典进行索引。当我需要通过特定键查找某些内容时,这非常有效,但有时情况并非如此。例如,我经常需要查找特定日期时间范围内的条目。有时我需要最低价格的条目。大多数情况下,查询会同时查看几个简单的键和一两个其他字段。
有没有任何工具、产品、库(针对 .NET 框架)可以帮助我解决这个问题?或者我是否需要拿起那本落满灰尘的旧算法书并开始研究搜索树?
示例:
Trip
- DepartureCode
- DestinationCode
- HotelCode
- RoomCode
- Date
- Price
我需要的查询类似于“为我提供 2010-03-09 至 2010-03-12 之间最便宜的旅行,其中 DepartureCode=LAX DestinationCode=纽约”
I have several medium-sized data sets in-memory that I need to be able to filter and find information from quickly. The data sets are small enough that I don't want to take the performance hit of going to a database every time I need an entry but large enough that I really need to index the data somehow.
Currently, I'm using POCO objects with one or more dictionaries for indexing. This works excellent when I need to find something by a specific key, but sometimes that isn't the case. As an example, I often need to find an entry within a specific date-time-range. And sometimes I need the entry with the lowest price. Most often, queries look at a few simple keys and one or two other fields at the same time.
Are there any tools, products, libraries (targeting the .NET-framework) that can help me with this? Or do I need to pick up that big dusty old Algorithms book and start looking at search-trees?
An example:
Trip
- DepartureCode
- DestinationCode
- HotelCode
- RoomCode
- Date
- Price
I need the query to be something like "get me the least expensive Trip between 2010-03-09 and 2010-03-12 where DepartureCode=LAX DestinationCode=NYC"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“最低价格”和“特定日期/时间范围”都可以仅使用排序集合和二分搜索来处理。
SortedList
/SortedDictionary
(或者SortedSet
,如果您使用的是 .NET 4.0)可能会在这里完成您需要的所有操作,只需相当少量的操作工作。"Lowest price" and "specific date/time range" can both be handled using just a sorted collection and binary search.
SortedList
/SortedDictionary
(orSortedSet
if you're using .NET 4.0) probably do everything you need here, with only a fairly small amount of work.DataSet.Table("YourTable").Select() 方法?
编辑:来自MSDN
因此,如果您想为 DataSet 建立索引,DataView 似乎可以为您提供这一服务。
How about the DataSet.Table("YourTable").Select() method?
EDIT: From MSDN
So if you're wanting to index your DataSet, it looks like a DataView could provide that for you.