Exemple #1
0
        /// <summary>Given an item and a leaf that is known to contain a copy of
        /// the item, this method returns the index of the item in the tree as
        /// a whole. Requires O(M )</summary>
        protected int ReconstructIndex(T item, AListLeaf <K, T> leaf)
        {
            AListInnerBase <K, T> inner;
            AListNode <K, T>      node;
            bool found;

            int index = leaf.IndexOf(item, 0), localIndex;

            if (index <= -1)
            {
                BadState();
            }

            node = leaf;
            while (node != _root)
            {
                Debug.Assert(node != null);
                _nodes.FindLowerBoundExact(ref node, out inner, out found);
                if (!found)
                {
                    BadState();
                }
                if ((localIndex = (int)inner.BaseIndexOf(node)) <= -1)
                {
                    BadState();
                }
                node   = inner;
                index += localIndex;
            }

            return(index);
        }
Exemple #2
0
        public void ItemRemoved(T item, AListLeaf <K, T> parent)
        {
            int index = _items.IndexOfExact(new KeyValuePair <T, AListLeaf <K, T> >(item, parent));

            if (index <= -1)
            {
                BadState();
            }
            _items.RemoveAt(index);
        }
Exemple #3
0
 public AListLeaf(AListLeaf <K, T> frozen)
 {
     // TODO: Rethink: original node doesn't have to be frozen because we are deep-cloning. Right??
     //       Probably DetachedClone() doesn't have to freeze a leaf node.
     Debug.Assert(frozen.IsFrozen);
     _list        = frozen._list.Clone();
     _maxNodeSize = frozen._maxNodeSize;
     _isFrozen    = false;
     //_userByte = frozen._userByte;
 }
Exemple #4
0
 public void ItemAdded(T item, AListLeaf <K, T> parent)
 {
     _items.Add(new KeyValuePair <T, AListLeaf <K, T> >(item, parent));
 }
 public static void ItemMoved <K, T>(this IAListTreeObserver <K, T> self, T item, AListLeaf <K, T> oldParent, AListLeaf <K, T> newParent)
 {
     self.ItemRemoved(item, oldParent);
     self.ItemAdded(item, newParent);
 }
 internal static void RemovingItems <K, T>(this IAListTreeObserver <K, T> self, InternalDList <T> list, int index, int count, AListLeaf <K, T> parent, bool isMoving)
 {
     for (int i = index; i < index + count; i++)
     {
         self.ItemRemoved(list[i], parent);
     }
 }
 internal static void AddingItems <K, T>(this IAListTreeObserver <K, T> self, ListSourceSlice <T> list, AListLeaf <K, T> parent, bool isMoving)
 {
     for (int i = 0; i < list.Count; i++)
     {
         self.ItemAdded(list[i], parent);
     }
 }