Пример #1
0
        void SortDown(CellData item)
        {
            int childIndexLeft  = item.HeapIndex * 2 + 1;
            int childIndexRight = item.HeapIndex * 2 + 2;
            int swapIndex       = 0;

            while (childIndexLeft < m_Count)
            {
                if (childIndexRight < m_Count && m_Items[childIndexLeft].CompareTo(ref m_Items[childIndexRight]) > 0)
                {
                    swapIndex = childIndexRight;
                }
                else
                {
                    swapIndex = childIndexLeft;
                }

                if (item.CompareTo(ref m_Items[swapIndex]) > 0)
                {
                    Swap(item, m_Items[swapIndex]);
                }
                else
                {
                    return;
                }

                childIndexLeft  = item.HeapIndex * 2 + 1;
                childIndexRight = item.HeapIndex * 2 + 2;
                swapIndex       = 0;
            }
        }
Пример #2
0
        void SortUp(CellData item)
        {
            int parentIndex = (item.HeapIndex - 1) / 2;
            var parentItem  = m_Items[parentIndex];

            while (item.CompareTo(ref parentItem) < 0)
            {
                Swap(item, parentItem);

                parentIndex = (item.HeapIndex - 1) / 2;
                parentItem  = m_Items[parentIndex];
            }
        }