【发布时间】:2012-02-13 17:30:50
【问题描述】:
假设我们有以下列表:
List<int> Journey1 = new List<int>() { 1, 2, 3, 4, 5 };
List<int> Journey2 = new List<int>() { 2, 3, 4, 6, 7, 3, 4 };
List<int> Journey3 = new List<int>() { 6, 7, 1 };
List<int> Journey4 = new List<int>() { 3, 1, 4 };
模式是:
2, 3, 4 -> Journey1, Journey2;
6, 7 -> Journey2, Journey3;
1 -> Journey2, Journey3, Journey4;
5 -> Journey1;
3, 4 -> Journey2;
3 -> Journey4;
4 -> Journey4;
我们有 5000 个列表,每个列表大约有 200 个项目,因此模式可以包含 1-200 个项目,并且可以在 1-5000 个列表中看到。
因此我需要非常快速的模式匹配方式。
【问题讨论】:
-
你能解释一下规则吗?例如。为什么不是
3 -> Journey1, Journey2, Journey4 -
哦,模式是(序列)=>(要搜索的列表列表)?
-
我们需要找到从最长到最短的模式,因此首先我选择了 2,3,4,这是在不止一次旅程中看到的最长模式。
标签: c# list pattern-matching