예제 #1
0
        /* really __gl_pqHeapInsert */
        /* returns LONG_MAX iff out of memory */
        internal override int pqInsert(System.Object keyNew)
        {
            int curr;
            int free;

            curr = ++size;
            if ((curr * 2) > max)
            {
                Mogre.Utils.GluTesselator.PriorityQ.PQnode[] saveNodes = nodes;
                Mogre.Utils.GluTesselator.PriorityQ.PQhandleElem[] saveHandles = handles;

                /* If the heap overflows, double its size. */
                max <<= 1;
                //            pq->nodes = (PQnode *)memRealloc( pq->nodes, (size_t) ((pq->max + 1) * sizeof( pq->nodes[0] )));
                PriorityQ.PQnode[] pqNodes = new PriorityQ.PQnode[max + 1];
                Array.Copy(nodes, 0, pqNodes, 0, nodes.Length);
                for (int i = nodes.Length; i < pqNodes.Length; i++)
                {
                    pqNodes[i] = new PQnode();
                }
                nodes = pqNodes;
                if (nodes == null)
                {
                    nodes = saveNodes; /* restore ptr to free upon return */
                    return System.Int32.MaxValue;
                }

                //            pq->handles = (PQhandleElem *)memRealloc( pq->handles,(size_t)((pq->max + 1) * sizeof( pq->handles[0] )));
                PriorityQ.PQhandleElem[] pqHandles = new PriorityQ.PQhandleElem[max + 1];
                Array.Copy(handles, 0, pqHandles, 0, handles.Length);
                for (int i = handles.Length; i < pqHandles.Length; i++)
                {
                    pqHandles[i] = new PQhandleElem();
                }
                handles = pqHandles;
                if (handles == null)
                {
                    handles = saveHandles; /* restore ptr to free upon return */
                    return System.Int32.MaxValue;
                }
            }

            if (freeList == 0)
            {
                free = curr;
            }
            else
            {
                free = freeList;
                freeList = handles[free].node;
            }

            nodes[curr].handle = free;
            handles[free].node = curr;
            handles[free].key = keyNew;

            if (initialized)
            {
                FloatUp(curr);
            }
            //assert(free != System.Int32.MaxValue);
            return free;
        }
예제 #2
0
        /* really __gl_pqHeapInsert */
        /* returns LONG_MAX iff out of memory */
        internal override int pqInsert(System.Object keyNew)
        {
            int curr;
            int free;

            curr = ++size;
            if ((curr * 2) > max)
            {
                Mogre.Utils.GluTesselator.PriorityQ.PQnode[]       saveNodes   = nodes;
                Mogre.Utils.GluTesselator.PriorityQ.PQhandleElem[] saveHandles = handles;

                /* If the heap overflows, double its size. */
                max <<= 1;
                //            pq->nodes = (PQnode *)memRealloc( pq->nodes, (size_t) ((pq->max + 1) * sizeof( pq->nodes[0] )));
                PriorityQ.PQnode[] pqNodes = new PriorityQ.PQnode[max + 1];
                Array.Copy(nodes, 0, pqNodes, 0, nodes.Length);
                for (int i = nodes.Length; i < pqNodes.Length; i++)
                {
                    pqNodes[i] = new PQnode();
                }
                nodes = pqNodes;
                if (nodes == null)
                {
                    nodes = saveNodes;                     /* restore ptr to free upon return */
                    return(System.Int32.MaxValue);
                }

                //            pq->handles = (PQhandleElem *)memRealloc( pq->handles,(size_t)((pq->max + 1) * sizeof( pq->handles[0] )));
                PriorityQ.PQhandleElem[] pqHandles = new PriorityQ.PQhandleElem[max + 1];
                Array.Copy(handles, 0, pqHandles, 0, handles.Length);
                for (int i = handles.Length; i < pqHandles.Length; i++)
                {
                    pqHandles[i] = new PQhandleElem();
                }
                handles = pqHandles;
                if (handles == null)
                {
                    handles = saveHandles;                     /* restore ptr to free upon return */
                    return(System.Int32.MaxValue);
                }
            }

            if (freeList == 0)
            {
                free = curr;
            }
            else
            {
                free     = freeList;
                freeList = handles[free].node;
            }

            nodes[curr].handle = free;
            handles[free].node = curr;
            handles[free].key  = keyNew;

            if (initialized)
            {
                FloatUp(curr);
            }
            //assert(free != System.Int32.MaxValue);
            return(free);
        }