Distributed numeric sequence class for .NET.

I need a very specific class, I would really like to know if it exists, so I do not need to reimplement it. I have a set of items. Each element has a numerical value associated with it - weight. The weight of each item is unique in the set. Items must be sorted by weight. Weight can be changed for each item, but the weight change operation is extremely expensive. There is an operation that is performed with a frequent set - moving the range of elements within the set by changing the weight of the element. Therefore, I need a class of the List class, but with built-in logic to control the weights of the elements. The sequence of weights must be sparse to minimize weight collisions during movement and to improve productivity while minimizing weight change operations. The class interface should look like this:

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.
}

Did not find anything like this in a wireframe or PowerCollections. I assume that you already realized that I intend to use this class to control the write operations in the backup database :) Thanks.

+3
1

SortedList<int, T>. , , . , .

+1

Source: https://habr.com/ru/post/1771691/


All Articles