与えられた:
IMatchCriteria {
string PropA{get;}
string PropB{get;}
int? PropC {get;}
int? PropD {get;}
}
IReportRecord : IMatchCriteria {...}
IMatchCriteriaSet : IMatchCriteria {
int MatchId {get;}
double Limit{get;}
}
public class Worker{
private List<IMatchCriteriaSet> _matchers = GetIt();
//Expecting this list to be huge, ***upto 0.1m***. Some of the sample matchers:
// MatchId=1, Limit=1000, PropA=A, PropC=101, PropD=201
// MatchId=2, Limit=10, PropA=A
// MatchId=3, Limit=20, PropC=101
// MatchId=4, Limit=500, PropD=201
//Based on sample entries:
//Input: reportRecord{ PropA=A, PropC=101 }, Ouput: 1000, 20
//Input: reportRecord{ PropA=A1, PropC=102, PropD=201 }, Ouput: 500
public IEnumerable<double> GetMatchingLimits(IReportRecord reportRecord) {
//Bad, very bad option:
foreach(var matcher in _matchers){
var matchFound=true;
if(reportRecord.PropA!=null && reportRecord.PropA!=matcher.PropA){
continue;
}
if(reportRecord.PropB!=null && reportRecord.PropA!=matcher.PropB){
continue;
}
if(reportRecord.PropC!=null && reportRecord.PropC.Value!=matcher.PropC.Value){
continue;
}
if(reportRecord.PropD!=null && reportRecord.PropD.Value!=matcher.PropD.Value){
continue;
}
yield return matcher.Limit;
}
}
}
注:IMatchCriteriaSetは0.1mレコードであると想定しています。GetMatchingLimitsが1m回呼び出されることを期待しています。要件は、リアルタイムアプリケーションに対してこれらすべてを実行することです。
基本的に私が必要としているのは、IMatchCriteriaのリストにインデックスを付ける方法です。しかし、私のキーが定義されていないため、辞書を使用できません。この問題に効率的に取り組むためのアルゴリズムを探しています。
(c#だけでなく).netの範囲で提案された解決策があれば便利です。
ありがとう。