非常に具体的なクラスが必要です。既存のクラスがあるかどうかを知りたいので、再実装する必要はありません。セット商品を持っています。各アイテムには、重量に関連付けられた数値があります。各アイテムの重量はセット内で固有です。アイテムは重量順に分類する必要があります。重量はアイテムごとに変更できますが、重量を変更する操作は非常にコストがかかります。セットで頻繁に実行される操作があります-アイテムの重みを変更することにより、セット内のアイテムの範囲を移動します。したがって、リストのようなクラスが必要ですが、アイテムの重みを管理するためのロジックが組み込まれています。移動操作での重みの衝突を最小限に抑え、重みの変更操作を最小限に抑えることでパフォーマンスを向上させるには、重みシーケンスをまばらにする必要があります。クラス インターフェイスは次のようになります。
public abstract class SparsedSequence<T> : IList<T>
{
// Weight increment for new items.
private int WeightIncrement = 10000;
protected abstract void OnWeightChanged(int weight, T item);
public void MoveRange(int offset, int count, int amount)
{
// There must be fancy weight management logic.
}
public void MoveRange(T[] range, int amount)
{
// Cut T[] to set of calls to MoveRange(int, int, int)
}
public int ConstraintAmount(int offset, int count, int amount)
{
// Returns amount constrainded by sequence size and 0,
// so that moved block will remain within proper range.
// If returns 0 - block unmovable in that direcion.
}
public int ConstraintAmount(T[] range, int amount)
{
// ----- " -----
}
public void Add(T newItem)
{
// Add to sequnce end.
// Defines new weight and calls OnWeightChanged.
// NewWeight = Weights[Count - 1] + WeightIncrement.
}
public void Add(T item, int weight)
{
// Adds item with forced weight.
}
public T this[int index]
{
// Get item
get { ... }
}
public IList<int> Weights
{
// Get items weights
get { ... }
}
public KeyValuePair<int, T> this[int index]
{
// Get item and weight
get { ... }
}
// Remove, clear, insert, indexof etc.
}
フレームワークまたは PowerCollections で同様のものは見つかりませんでした。このクラスを使用して、データベースの順序付けられたレコード セットの操作を管理するつもりであることは、すでにご理解いただけたと思います :) ありがとうございます。