私はC#にかなり慣れていないので、問題があります。2 つの SortedSet を多数の (数千の) カスタム オブジェクトで埋めました。他の SortedSet を反復処理せずにすばやくアクセスする関数を作成しようとしています (反復処理には時間がかかりすぎて、約 40 秒かかります)。セットを名前で並べ替え、次にインターフェイスを使用して展開します。
public int CompareTo(card other)
{
if (string.Compare(this.name,other.name)>0)
return 1;
if (string.Compare(this.name, other.name) < 0)
return -1;
else if (string.Compare(this.expansion, other.expansion) > 0)
return 1;
else if (string.Compare(this.expansion, other.expansion) < 0)
return -1;
else
return 0;
} // in my obj declaration.
//and the following for declaring the sortedset:
public SortedSet<card> MM = new SortedSet<card>();
public SortedSet<card> MMother = new SortedSet<card>();
//i can do the following:
int counter=0;
foreach (card thing in MM) //took only .7 seconds
{
if(thing.IsProperSubsetOf(MMother))
counter++;
}
これは問題なく動作しますが、オブジェクトには名前と展開だけでなく、price= 10 、 owner = "jack" などの他の属性も含まれているため、id は反復せずにそれらにアクセスするのが好きです。何かのようなもの:
int price = (MMother.matches(card)-->戻り値)
しかし、私はこれを行う方法がわかりません。任意のヒント?