public void Detach(AListBase <K, T> list, AListNode <K, T> root) { Assert.ReferenceEquals(list, _list); Assert.ReferenceEquals(root, _root); RootChanged(_list, null, true); _list = null; }
/// <summary>Allows derived classes of AListNode to fire the AListBase.ListChanging event properly.</summary> protected void CallListChanging(AListBase <K, T> tree, ListChangeInfo <T> listChangeInfo) { if (tree._listChanging != null) { tree.CallListChanging(listChangeInfo); } }
public ObserverMgr(AListBase <K, T> list, AListNode <K, T> root, IAListTreeObserver <K, T> existingObserver) { _list = list; _root = root; if (existingObserver != null) { _observers.Add(existingObserver); } }
public override AListNode <K, T> CopySection(uint index, uint count, AListBase <K, T> list) { Debug.Assert((int)(count | index) > 0); if (index == 0 && count == _list.Count) { return(DetachedClone()); } return(new BListLeaf <K, T>(_maxNodeSize, _list.CopySection((int)index, (int)count))); }
public override AListNode <int, T> CopySection(uint index, uint count, AListBase <int, T> list) { Debug.Assert(count > 0 && count <= TotalCount); if (index == 0 && count >= TotalCount) { return(DetachedClone()); } return(new AListInner <T>(this, index, count, list)); }
public override AListNode <int, T> CopySection(uint index, uint count, AListBase <int, T> list) { int i1, i2; i1 = GetSectionRange(index, count, out i2); InternalDList <Entry> section = _list.CopySection(i1, i2 - i1); AdjustOffsetsStartingAt(0, ref section, -(int)index); return(new SparseAListLeaf <T>(_maxNodeSize, section, count)); }
public void RootChanged(AListBase <K, T> list, AListNode <K, T> newRoot, bool clear) { if (newRoot == null) { if (!clear && _items.Count != 0) { BadState(); } _items.Clear(); _nodes = null; } _root = newRoot; }
public void RootChanged(AListBase <K, T> list, AListNode <K, T> newRoot, bool clear) { Assert.ReferenceEquals(list, _list); if (clear) { ItemCount = NodeCount = 0; } else if (newRoot == null) { Assert.AreEqual(0, ItemCount); Assert.AreEqual(0, NodeCount); } _root = newRoot; }
protected void VerifyLeafCapacityLimitIsRespected <K>(AListBase <K, T> list, int maxLeafSize) { foreach (var leaf in list._root.Leaves) { if (leaf is SparseAListLeaf <T> ) { Assert.LessOrEqual(((SparseAListLeaf <T>)(object) leaf)._list.Capacity, maxLeafSize); } else { Assert.LessOrEqual(((AListLeaf <K, T>)leaf)._list.Capacity, maxLeafSize); } } }
public bool?Attach(AListBase <K, T> list) { Assert.That(_list == null && _root == null); _list = list; return(true); }
public void Detach(AListBase <K, T> list, AListNode <K, T> root) => RootChanged(list, null, true);
protected AListInner(AListInner <T> original, uint index, uint count, AListBase <int, T> list) : base(original, index, count, list) { }
internal static void DoAttach <K, T>(this IAListTreeObserver <K, T> observer, AListNode <K, T> root, AListBase <K, T> list) { observer.Attach(list, childrenFirst => { observer.RootChanged(root, false); if (root != null) { AddAllRecursively(observer, childrenFirst, root); } }); }
protected AList(AListBase <T, T> original, AListNode <T, T> section) : base(original, section) { }
public void Detach() { this.RootChanged(null, true); this._list = null; }
internal static void HandleRootSplit <K, T>(this IAListTreeObserver <K, T> self, AListBase <K, T> list, AListNode <K, T> oldRoot, AListNode <K, T> newLeft, AListNode <K, T> newRight, AListInnerBase <K, T> newRoot) { self.HandleNodeReplaced(oldRoot, newLeft, newRight); self.NodeAdded(newLeft, newRoot); self.NodeAdded(newRight, newRoot); self.RootChanged(list, newRoot, false); }
public bool?Attach(AListBase <K, T> list) => true;
/// <summary>Allows derived classes of AListNode to fire the AListBase.ListChanging event.</summary> protected bool HasListChanging(AListBase <K, T> tree) { return(tree._listChanging != null); }
/// <summary>Extracts and returns, as fast as possible, a subrange of the /// list that this node represents.</summary> /// <param name="index">Index to start copying</param> /// <param name="count">Number of Ts to copy (must be greater than zero).</param> /// <param name="list">List that is making the request. This parameter /// may be needed by organized trees that need to call list.GetKey().</param> /// <remarks>This method may return a size-one inner node that the caller /// must replace with its child. It will fast-clone any nodes that can be /// copied in their entirety, including this node itself.</remarks> public abstract AListNode <K, T> CopySection(uint index, uint count, AListBase <K, T> list);
public void Attach(AListBase <K, T> list, Action <bool> populate) { populate(true); }
public void Attach(AListBase <K, T> list, Action <bool> populate) { throw new InvalidOperationException(); // should not be called }
protected K GetKey(AListBase <K, T> tree, T item) { return(tree.GetKey(item)); }
/// <summary>Allows derived classes of AListNode to access AListBase._observer.</summary> protected IAListTreeObserver <K, T> GetObserver(AListBase <K, T> tree) { return(tree._observer); }
protected BListInner(BListInner <K, T> original, uint index, uint count, AListBase <K, T> list) : base(original, index, count, list) { // This constructor is called by CopySection GetHighestKeys(); }
public override AListNode <K, KeyValuePair <K, V> > CopySection(uint index, uint count, AListBase <K, KeyValuePair <K, V> > list) { Debug.Assert(count > 0 && count <= TotalCount); if (index == 0 && count >= TotalCount) { return(DetachedClone()); } return(new BDictionaryInner <K, V>(this, index, count, list)); }
internal static void HandleRootUnsplit <K, T>(this IAListTreeObserver <K, T> self, AListBase <K, T> list, AListInnerBase <K, T> oldRoot, AListNode <K, T> newRoot) { Debug.Assert(oldRoot.LocalCount == 0 || (oldRoot.LocalCount == 1 && oldRoot.Child(0) == newRoot)); self.NodeRemoved(newRoot, oldRoot); self.RootChanged(list, newRoot, false); }
protected BDictionaryInner(BDictionaryInner <K, V> original, uint index, uint count, AListBase <K, KeyValuePair <K, V> > list) : base(original, index, count, list) { }
public void Attach(AListBase <K, T> list, Action <bool> populate) { Assert.That(this._list == null && this._root == null); this._list = list; populate(true); }
protected AListInnerBase(AListInnerBase <K, T> original, uint index, uint count, AListBase <K, T> list) { // This constructor is called by CopySection Debug.Assert(count > 0 && count <= original.TotalCount); int i0 = original.BinarySearchI(index); int iN = original.BinarySearchI(index + count - 1); Entry e0 = original._children[i0]; Entry eN = original._children[iN]; int localCount = iN - i0 + 1; // round up size to the nearest 4. _children = new Entry[(localCount + 3) & ~3]; _isFrozen = false; _maxNodeSize = original._maxNodeSize; //_userByte = original._userByte; _childCount = (byte)localCount; InitEmpties(iN - i0 + 1); if (i0 == iN) { _children[0].Node = e0.Node.CopySection(index - e0.Index, count, list); } else { uint adjusted0 = index - e0.Index; uint adjustedN = index + count - eN.Index; Debug.Assert(adjusted0 <= index && adjustedN < count); AListNode <K, T> child0 = e0.Node.CopySection(adjusted0, e0.Node.TotalCount - adjusted0, list); AListNode <K, T> childN = eN.Node.CopySection(0, adjustedN, list); _children[0].Node = child0; _children[iN - i0].Node = childN; uint offset = child0.TotalCount; for (int i = i0 + 1; i < iN; i++) { AListNode <K, T> childI = original._children[i].Node; // Freeze child because it will be shared between the original // list and the section being copied childI.Freeze(); _children[i - i0] = new Entry { Node = childI, Index = offset }; offset += childI.TotalCount; } _children[iN - i0].Index = offset; // Finally, if the first/last node is undersized, redistribute items. // Note: we can set the 'tob' parameter to null because this // constructor is called by CopySection, which creates an // independent AList that does not have an indexer. while (_childCount > 1 && _children[0].Node.IsUndersized) { HandleUndersized(0, null); } while (_childCount > 1 && _children[_childCount - 1].Node.IsUndersized) { HandleUndersized(_childCount - 1, null); } } AssertValid(); }
internal static void Clear <K, T>(this IAListTreeObserver <K, T> self, AListBase <K, T> list) { self.RootChanged(list, null, true); }