public void ClearSpace(int index, int count = 1) { CheckParam.IsNotNegative("count", count); AutoThrow(); int end = checked (index + count); if (end > Count) { CheckParam.IsNotNegative("index", index); // this is also checked by DoSparseOperation if (index >= Count) { InsertSpace(Count, end - Count); return; } else { InsertSpace(Count, end - Count); } } if (count == 0) { return; } var op = new AListSparseOperation <T>((uint)index, false, true, count, _observer); DoSparseOperation(ref op); }
public sealed override bool TrySet(int index, T value) { if (_freezeMode != 0) { if (_freezeMode == FrozenForConcurrency) { AutoThrow(); } if (_freezeMode == Frozen) { return(false); } } if ((uint)index >= (uint)Count) { return(false); } var op = new AListSparseOperation <T>((uint)index, false, false, 1, _observer) { Item = value }; DoSparseOperation(ref op); return(true); }
public void InsertSpace(int index, int count = 1) { CheckParam.IsNotNegative("count", count); //CheckParam.IsInRange("index", index, 0, Count); checked by DoSparseOperation AutoThrow(); var newCount = checked (Count + count); var op = new AListSparseOperation <T>((uint)index, true, true, count, _observer); DoSparseOperation(ref op); }
public sealed override void Insert(int index, T item) { AutoThrow(); int newCount = checked (Count + 1); var op = new AListSparseOperation <T>((uint)index, true, false, 1, _observer) { Item = item }; DoSparseOperation(ref op); }
internal void DoSparseOperation(ref AListSparseOperation <T> op) { uint index = op.AbsoluteIndex; Debug.Assert((_freezeMode & 1) == 0); if ((uint)index > (uint)_count) { throw new ArgumentOutOfRangeException("index"); } Debug.Assert(op.SourceCount > 0); Debug.Assert(op.SourceCount <= (int)(_count - index) || op.IsInsert); if (_listChanging != null) { if (op.Source == null) { op.Source = new Repeated <T>(op.WriteEmpty ? default(T) : op.Item, op.SourceCount); } if (op.IsInsert) { CallListChanging(new ListChangeInfo <T>(NotifyCollectionChangedAction.Add, (int)index, op.SourceCount, op.Source)); } else { CallListChanging(new ListChangeInfo <T>(NotifyCollectionChangedAction.Replace, (int)index, 0, op.Source)); } } if (_root == null || _root.IsFrozen) { AutoCreateOrCloneRoot(); } AListNode <int, T> splitLeft, splitRight; int sizeChange = 0; do { sizeChange += _root.DoSparseOperation(ref op, (int)index, out splitLeft, out splitRight); if (splitLeft != null) { AutoSplit(splitLeft, splitRight); } } while (op.SourceIndex < op.SourceCount); _count += (uint)sizeChange; Debug.Assert(sizeChange == (op.IsInsert ? op.SourceCount : 0)); ++_version; CheckPoint(); }
public sealed override T this[int index] { get { return(((AListBase <int, T>) this)[index]); } set { if ((_freezeMode & 1) != 0) // Frozen or FrozenForConcurrency, but not FrozenForListChanging { AutoThrow(); } var op = new AListSparseOperation <T>((uint)index, false, false, 1, _observer) { Item = value }; DoSparseOperation(ref op); } }
public void InsertRange(int index, ISparseListSource <T> list) { AutoThrow(); var count = list.Count; DetectSizeOverflow(count); if (count <= 0) { return; } var op = new AListSparseOperation <T>((uint)index, true, false, count, _observer) { Source = list, SparseSource = list }; DoSparseOperation(ref op); }
public sealed override void InsertRange(int index, IListSource <T> list) { AutoThrow(); var count = list.Count; int newCount = checked (Count + count); if (count <= 0) { return; } var op = new AListSparseOperation <T>((uint)index, true, false, count, _observer) { Source = list, SparseSource = list as ISparseListSource <T> }; DoSparseOperation(ref op); }