从内存数据集中过滤和查找

发布于 2024-08-24 01:30:53 字数 558 浏览 15 评论 0原文

我的内存中有几个中等大小的数据集,我需要能够快速过滤和查找信息。数据集足够小,我不想每次需要一个条目时都访问数据库,但又足够大,我确实需要以某种方式索引数据。

目前,我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼波传意 2024-08-31 01:30:53

“最低价格”和“特定日期/时间范围”都可以仅使用排序集合和二分搜索来处理。 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 (or SortedSet if you're using .NET 4.0) probably do everything you need here, with only a fairly small amount of work.

笔落惊风雨 2024-08-31 01:30:53

DataSet.Table("YourTable").Select() 方法?

Dim myRows() as DataRow = myDataSet.Tables("myTable").Select("Date>" & _
    myBeginDate & "AND Date<" & myEndDate)

编辑:来自MSDN

数据视图构建

DataView 为
底层 DataTable 中的数据时
DataView 被创建,并且何时
Sort、RowFilter 或 RowStateFilter
属性被修改。创建时
DataView 对象,使用 DataView
接受排序的构造函数,
RowFilter 和 RowStateFilter 值
作为构造函数参数(以及
底层数据表)。结果
是索引建立一次。创造
一个“空”DataView 并设置
排序、RowFilter 或 RowStateFilter
属性之后的结果是
索引至少构建两次。

因此,如果您想为 DataSet 建立索引,DataView 似乎可以为您提供这一服务。

How about the DataSet.Table("YourTable").Select() method?

Dim myRows() as DataRow = myDataSet.Tables("myTable").Select("Date>" & _
    myBeginDate & "AND Date<" & myEndDate)

EDIT: From MSDN

DataView Construction

The DataView builds an index for the
data in the underlying DataTable when
both the DataView is created, and when
the Sort, RowFilter or RowStateFilter
properties are modified. When creating
a DataView object, use the DataView
constructor that takes the Sort,
RowFilter, and RowStateFilter values
as constructor arguments (along with
the underlying DataTable). The result
is the index is built once. Creating
an "empty" DataView and setting the
Sort, RowFilter or RowStateFilter
properties afterward results in the
index being built at least twice.

So if you're wanting to index your DataSet, it looks like a DataView could provide that for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文