/// <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(); }
public void RemoveRange(int index, int removeItesCount) { IndexStorage.CheckIndex(index, this.size); IndexStorage.CheckIndex(index + removeItesCount, this.size); Array.Copy(this.storage, index + removeItesCount, this.storage, index, this.storage.Length - index - removeItesCount); Array.Copy(this.indicesWithValue, index + removeItesCount, this.indicesWithValue, index, this.indicesWithValue.Length - index - removeItesCount); for (int i = this.storage.Length - 1; i >= this.storage.Length - removeItesCount; i--) { this[i] = 0; this.indicesWithValue[i] = false; } this.count -= removeItesCount; this.RefreshAggregateInfo(); }
// Indexer will return average item length if IndexStorage.UnknownItemLength is found. // this.storage will return the actual stored value. // Use indexer to approximate the entire length. private long this[int index] { get { IndexStorage.CheckIndex(index, this.size); long val = this.storage[index]; return(val != IndexStorage.DoubleToLong(IndexStorage.UnknownItemLength, IndexStorage.PrecisionMultiplier) ? val : this.averageItemLength); } set { IndexStorage.CheckIndex(index, this.size); IndexStorage.CheckValue(value); long item = this.storage[index]; if (item == value) { return; } if (LongToDouble(item, IndexStorage.PrecisionMultiplier) == IndexStorage.UnknownItemLength) { this.knownSizeItemsCount++; } if (this.knownSizeItemsCount == 0) { this.averageItemLength = IndexStorage.DefaultAverageItemLength; } else { this.averageItemLength = (long)(this.averageItemLength * (this.knownSizeItemsCount - 1) + value) / this.knownSizeItemsCount; } this.Set(index, value); if (!this.initializeStorageInProgress) { this.RefreshAggregateInfo(); } } }