Esempio n. 1
0
        int[] Heapsort([ReadOnly] ref Unity.Entities.ComponentDataArray <DistanceFromCameraData> distances)
        {
            int count = distances.Length;

            int[] sort = new int[count];

            for (int Indx = 0; Indx < count; ++Indx)
            {
                sort[Indx] = Indx;
            }

            for (int i = count >> 1; i >= 0; i--)
            {
                adjust(i, count - 1, ref sort, ref distances);
            }

            for (int i = count - 2; i >= 0; i--)
            {
                int swap = sort[i + 1];
                sort[i + 1] = sort[0];
                sort[0]     = swap;
                adjust(0, i, ref sort, ref distances);
            }

            return(sort);
        }
Esempio n. 2
0
        void adjust(int i, int n, ref int[] sort, [ReadOnly] ref Unity.Entities.ComponentDataArray <DistanceFromCameraData> distances)
        {
            int iPosition;
            int iChange;

            iPosition = sort[i];
            iChange   = 2 * i;
            while (iChange <= n)
            {
                if (iChange < n && distances[sort[iChange]].Value > distances[sort[iChange + 1]].Value)
                {
                    iChange++;
                }
                if (distances[iPosition].Value <= distances[sort[iChange]].Value)
                {
                    break;
                }
                sort[iChange >> 1] = sort[iChange];
                iChange          <<= 1;
            }
            sort[iChange >> 1] = iPosition;
        }