コード例 #1
0
 // Bubble-down / down-heap / percolate-down / sift-down operation
 private void BubbleDown(T item, int i, int count)
 {
     for (int ichild = i * 2 + 1, cmp; ichild < count; ichild = i * 2 + 1)
     {
         T c1 = _list[ichild], c2, biggerChild = c1;
         if (ichild + 1 < count)
         {
             c2  = _list[ichild + 1];
             cmp = _cmp.Compare(c1, c2);
             if (cmp < 0)
             {
                 biggerChild = c2;
                 ichild++;
             }
         }
         if (_cmp.Compare(item, biggerChild) >= 0)
         {
             break;
         }
         _list[i] = biggerChild;
         OnItemMoved?.Invoke(biggerChild, i);
         i = ichild;
     }
     _list[i] = item;
     OnItemMoved?.Invoke(item, i);
 }
コード例 #2
0
            private void Source_CollectionChanged(object aSender, NotifyCollectionChangedEventArgs aArgs)
            {
                switch (aArgs.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    //CheckOneOrNone(aArgs.NewItems);
                    OnItemAdded?.Invoke(Source, aArgs.NewStartingIndex, (T)aArgs.NewItems[0]);
                    break;

                case NotifyCollectionChangedAction.Move:
                    //CheckOneOrNone(aArgs.NewItems);
                    OnItemMoved?.Invoke(Source, aArgs.OldStartingIndex, aArgs.NewStartingIndex, (T)aArgs.NewItems[0]);
                    break;

                case NotifyCollectionChangedAction.Remove:
                    //CheckOneOrNone(aArgs.OldItems);
                    OnItemRemoved?.Invoke(Source, aArgs.OldStartingIndex, (T)aArgs.OldItems[0]);
                    break;

                case NotifyCollectionChangedAction.Replace:
                    //CheckOneOrNone(aArgs.NewItems);
                    OnItemReplaced?.Invoke(Source, aArgs.OldStartingIndex, (T)aArgs.OldItems[0], (T)aArgs.NewItems[0]);
                    break;

                case NotifyCollectionChangedAction.Reset:
                    OnCleared?.Invoke(Source);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
コード例 #3
0
        /// <summary>Combines a pop followed by a push into one operation that is more
        /// efficient than a separate <see cref="Pop"/> nad <see cref="Push(T)"/>.</summary>
        public T PopAndPush(T item)
        {
            T result = _list[0];

            OnItemMoved?.Invoke(result, -1);
            BubbleDown(item, 0, _list.Count);
            return(result);
        }
コード例 #4
0
        //아이템 이동 (아이템 -> 빈 슬롯)
        public void Move(SlotItem selectedItem, InventorySlot targetSlot)
        {
            int originIndex = selectedItem.Index;

            targetSlot.slotManager.LastRefreshedTab.ItemTable[targetSlot.Index] = selectedItem;
            selectedItem.Tab[originIndex] = null;

            selectedItem.Index = targetSlot.Index;
            selectedItem.Tab   = targetSlot.slotManager.LastRefreshedTab;

            OnItemMoved?.Invoke(selectedItem);
        }
コード例 #5
0
        /// <summary>Removes the largest item from the heap (or smallest item, if this is a MinHeap).</summary>
        /// <exception cref="EmptySequenceException">Thrown if the List is empty.</exception>
        public T Pop()
        {
            int count = _list.Count - 1;

            if (count < 0)
            {
                throw new EmptySequenceException();
            }
            var result = _list[0];

            BubbleDown(_list[count], 0, count);
            _list.RemoveAt(count);
            OnItemMoved?.Invoke(result, -1);
            return(result);
        }
コード例 #6
0
        /// <summary>Removes the largest item from the heap (or smallest item, if this is a MinHeap).</summary>
        /// <param name="isEmpty">Set to true if the heap is empty, false if not.</param>
        /// <returns>The popped value, or default(T) if the List was empty.</returns>
        public T TryPop(out bool isEmpty)
        {
            int count = _list.Count - 1;

            if (isEmpty = count < 0)
            {
                return(default(T));
            }
            var result = _list[0];

            BubbleDown(_list[count], 0, count);
            _list.RemoveAt(count);
            OnItemMoved?.Invoke(result, -1);
            return(result);
        }
コード例 #7
0
        // Bubble-up / up-heap / percolate-up / sift-up operation
        private int BubbleUp(int index, T item)
        {
            T   parent;
            int iParent = (index - 1) >> 1;

            while (index > 0 && _cmp.Compare(item, parent = _list[iParent]) > 0)
            {
                _list[index] = parent;
                OnItemMoved?.Invoke(parent, index);
                index   = iParent;
                iParent = (iParent - 1) >> 1;
            }
            _list[index] = item;
            OnItemMoved?.Invoke(item, index);
            return(index);
        }
コード例 #8
0
        public void MoveTo(IItemContainer newLocation)
        {
            if (Location == newLocation || !newLocation.FitsInSlot(this))
            {
                return;
            }

            OnItemMoved?.Invoke(this, new ItemMovedEventArgs
            {
                From = Location,
                To   = newLocation,
                Item = this
            });

            int maxAdded = newLocation.Add(this);

            Location?.Remove(this);
            if (maxAdded < Count)
            {
                new DroppableItem(this, Count - maxAdded, Location);
                Count = maxAdded;
            }
            Location = newLocation;
        }
コード例 #9
0
 public static void FireItemMoved(TrinityItem item)
 {
     Core.Logger.Log(LogCategory.ItemEvents, $"ItemMoved {item.Name}");
     OnItemMoved?.Invoke(item);
 }