Пример #1
0
        public void ResetToDefaultValues(IRenderInfoState loadState, double defaultValue)
        {
            this.Clear();

            long itemLength = double.IsNaN(defaultValue) ? this.itemDefaultValue : IndexStorage.DoubleToLong(defaultValue, IndexStorage.PrecisionMultiplier);

            this.Initialize(loadState, this.Count, itemLength);
        }
Пример #2
0
        public double ValueForIndex(int index, bool approximate = true)
        {
            if (approximate || this.indicesWithValue[index])
            {
                return(IndexStorage.LongToDouble(this[index], IndexStorage.PrecisionMultiplier));
            }

            return(0.0);
        }
Пример #3
0
 private long this[int index]
 {
     get
     {
         IndexStorage.CheckIndex(index, this.size);
         return(this.storage[index]);
     }
     set
     {
         IndexStorage.CheckIndex(index, this.size);
         IndexStorage.CheckValue(value);
         this.Set(index, value);
     }
 }
Пример #4
0
        /// <summary>
        /// Removes the element at the given index. Worst complexity is
        /// (N-InsertIndex) + Log(N)*NonDefaultsInRange(N-InsertIndex).
        /// </summary>
        /// <param name="index">The index at which to remove the item.</param>
        public void RemoveAt(int index)
        {
            IndexStorage.CheckIndex(index, this.size);

            Array.Copy(this.storage, index + 1, this.storage, index, this.storage.Length - index - 1);
            Array.Copy(this.indicesWithValue, index + 1, this.indicesWithValue, index, this.indicesWithValue.Length - index - 1);

            if (this.count > 0)
            {
                this[this.count - 1] = 0;
                this.count--;
            }

            this.RefreshAggregateInfo();
        }
Пример #5
0
        public void Add(double value)
        {
            long val = IndexStorage.DoubleToLong(value, IndexStorage.PrecisionMultiplier);

            IndexStorage.CheckValue(val);

            if (this.Count == this.size)
            {
                this.ExtendCapacity(this.size * 2);
                this.RefreshAggregateInfo();
            }

            this.count++;
            this[this.Count - 1] = val;
        }
Пример #6
0
        public double OffsetFromIndex(int endIndex)
        {
            ////IndexStorage.CheckIndex(endIndex, this.size);

            if (this.aggregateInfoUpdateInProgress)
            {
                Debugger.Break();
            }

            var index = endIndex;

            // Debug.Assert is not enough!
            // in some cases like continuous adding of a new item (ShowInsertRow = true)
            // without these two checks exception is thrown
            if (index < 0)
            {
                return(this.storage[0]);
            }

            if (index >= this.storage.Length)
            {
                return(this.storage[this.storage.Length - 1]);
            }

            long result = this.storage[index];

            if ((index % 2) == 1)
            {
                result += this.storage[index - 1];
            }

            index = (index + this.size) >> 1;

            while (index != 1)
            {
                bool comeFromRight = index % 2 == 1;
                if (comeFromRight)
                {
                    result += this.aggregateInfo[index - 1];
                }
                index >>= 1;
            }

            return(IndexStorage.LongToDouble(result, IndexStorage.PrecisionMultiplier));
        }
Пример #7
0
        public int IndexFromOffset(double offset)
        {
            if (this.aggregateInfoUpdateInProgress)
            {
                Debugger.Break();
            }

            long value = IndexStorage.DoubleToLong(offset, IndexStorage.PrecisionMultiplier);

            if (value > this.aggregateInfo[1])
            {
                return(this.count - 1);
            }
            int index = 1;

            while (index * 2 < this.size)
            {
                if (this.aggregateInfo[index * 2] < value)
                {
                    value -= this.aggregateInfo[index * 2];
                    index  = (index * 2) + 1;
                }
                else
                {
                    index *= 2;
                }
            }

            index = (index * 2) - this.size;

            while (index < this.size)
            {
                if (this.storage[index] < value)
                {
                    value -= this.storage[index];
                    index++;
                }
                else
                {
                    break;
                }
            }

            return(Math.Min(index, this.count - 1));
        }
Пример #8
0
        public void RemoveRange(int index, int removeItemsCount)
        {
            IndexStorage.CheckIndex(index, this.size);
            IndexStorage.CheckIndex(index + removeItemsCount, this.size);

            Array.Copy(this.storage, index + removeItemsCount, this.storage, index, this.storage.Length - index - removeItemsCount);
            Array.Copy(this.indicesWithValue, index + removeItemsCount, this.indicesWithValue, index, this.indicesWithValue.Length - index - removeItemsCount);

            for (int i = this.storage.Length - 1; i >= this.storage.Length - removeItemsCount; i--)
            {
                this.storage[i]          = 0;
                this.indicesWithValue[i] = false;
            }

            this.count -= removeItemsCount;

            this.RefreshAggregateInfo();
        }
Пример #9
0
        internal IndexStorage(int capacity, double defaultVal)
        {
            this.itemDefaultValue = IndexStorage.DoubleToLong(defaultVal, IndexStorage.PrecisionMultiplier);

            IndexStorage.CheckValue(this.itemDefaultValue);

            this.count = capacity;
            this.size  = 8;
            while (this.size <= capacity)
            {
                this.size <<= 1;
            }

            this.indicesWithValue = new bool[this.size];
            this.storage          = new long[this.size];
            this.aggregateInfo    = new long[this.size];

            this.Initialize(null, capacity, this.itemDefaultValue);
        }
Пример #10
0
        public void Insert(int index, double value)
        {
            long val = IndexStorage.DoubleToLong(value, IndexStorage.PrecisionMultiplier);

            IndexStorage.CheckValue(val);

            if (this.Count + 1 == this.size)
            {
                this.ExtendCapacity(this.size * 2);
            }

            Array.Copy(this.storage, index, this.storage, index + 1, this.size - index - 1);
            Array.Copy(this.indicesWithValue, index, this.indicesWithValue, index + 1, this.size - index - 1);

            this.RefreshAggregateInfo();

            this.count++;
            this[index] = val;
        }
Пример #11
0
        public void InsertRange(int index, double?value, int insertItemsCount)
        {
            long val = 0;

            if (value.HasValue)
            {
                val = IndexStorage.DoubleToLong(value.Value, IndexStorage.PrecisionMultiplier);

                IndexStorage.CheckValue(val);
            }

            int newSize = this.size;

            while (this.Count + insertItemsCount >= newSize)
            {
                newSize *= 2;
            }

            if (newSize != this.size)
            {
                this.ExtendCapacity(newSize);
            }

            Array.Copy(this.storage, index, this.storage, index + insertItemsCount, this.size - index - insertItemsCount);
            Array.Copy(this.indicesWithValue, index, this.indicesWithValue, index + insertItemsCount, this.size - index - insertItemsCount);

            this.count += insertItemsCount;

            for (int i = 0; i < insertItemsCount; i++)
            {
                if (value.HasValue)
                {
                    this.storage[index + i]          = val;
                    this.indicesWithValue[index + i] = true;
                    this.HasUpdatedValues            = true;
                }
            }

            this.RefreshAggregateInfo();
        }
Пример #12
0
        private void Initialize(IRenderInfoState loadState, int capacity, long defaultValue)
        {
            if (defaultValue != 0)
            {
                var currentValue = defaultValue;

                for (int i = 0; capacity > 0; i++)
                {
                    if (loadState != null)
                    {
                        var loadValue = loadState.GetValueAt(i);

                        currentValue = loadValue.HasValue ? IndexStorage.DoubleToLong(loadValue.Value, IndexStorage.PrecisionMultiplier) : defaultValue;
                    }

                    this.storage[i] = currentValue;
                    capacity--;
                }

                this.RefreshAggregateInfo();
            }
        }
Пример #13
0
 public void Update(int index, double value)
 {
     this[index] = IndexStorage.DoubleToLong(value, IndexStorage.PrecisionMultiplier);
 }