Esempio n. 1
0
        public void AddAfter_ItemInListWithPromotions_UpdatesParents()
        {
            CreateThreeLevelTree(1);
            _coinFlipper.DefaultFlip = true;

            IndexingSkipList <object> .Node newNode = _target.AddAfter(_leaves[1], 2, _values[0]);

            Assert.AreEqual(_values[0], newNode.Value);

            Assert.AreEqual(2, newNode.ItemsInNode);
            Assert.AreEqual(3, newNode.Above.ItemsInNode);
            Assert.AreEqual(1, _leaves[1].Above.ItemsInNode);

            AssertLinked(_leaves[1], newNode);
            AssertLinked(_leaves[1].Above, newNode.Above);
            AssertLinked(_headers[0], newNode.Above.Above);
            AssertLinked(_headers[0].Above, newNode.Above.Above.Above);
        }
        private IndexingSkipList <IList <TResult> > .Node RecordItem(IndexingSkipList <IList <TResult> > .Node nodeBefore, TSource item, IList <TResult> collection)
        {
            int count   = GetCount(collection);
            var newNode = _collectionIndex.AddAfter(nodeBefore, count, collection);

            RecordNodeForItemInLookupTables(item, collection, newNode);

            if (collection != null && !_weakEventHandlers.ContainsKey(collection))
            {
                WeakEventHandler weakEventHandler = WeakNotifyCollectionChangedEventHandler.Register(
                    (INotifyCollectionChanged)collection,
                    this,
                    (me, sender, args) => me.OnSubCollectionChanged(sender, args));

                _weakEventHandlers.Add(collection, weakEventHandler);
            }

            return(newNode);
        }