예제 #1
0
        public void             shrink()                        // decrease size of array A
        {                                                       // O(k) time
            tuple newtuple;

            hnode[] B;                                                          // scratch space for contraction of A
            B = new hnode [heaplimit];                                          //
            for (int i = 0; i < heaplimit; i++)
            {
                B[i].d = A[i].d;
            }                                                      // copy A into B
            // delete old array of addresses
            A = new hnode [arraysize / 2];                         // shrink A by factor of 2
            for (int i = 0; i < heaplimit; i++)
            {
                A[i].d = B[i].d;
            }                                                      // copy B into A
            for (int i = heaplimit; i < (arraysize / 2); i++)      // initialize new heap values
            {
                newtuple = new tuple();                            //
                A[i].d   = newtuple;                               //
                A[i].d.m = -4294967296.0;                          //
                A[i].d.i = 0;                                      //
                A[i].d.j = 0;                                      //
                A[i].d.k = i;                                      //
            }
            // delete scratch space B
            arraysize = arraysize / 2;                                                    // update size of array
            return;
        }
예제 #2
0
        public void grow()  //increase size of array A
        {
            tuple newtuple;

            hnode[] B;                                                          // scratch space for expansion of A
            B = new hnode [arraysize];                                          //
            for (int i = 0; i < arraysize; i++)
            {
                B[i].d = A[i].d;
            }                                                      // copy A into B
            // delete old array of addresses
            A = new hnode [2 * arraysize];                         // grow A by factor of 2
            for (int i = 0; i < arraysize; i++)
            {
                A[i].d = B[i].d;
            }                                                      // copy B into first half of A
            for (int i = arraysize; i < (2 * arraysize); i++)      // initialize new heap values
            {
                newtuple = new tuple();                            //
                A[i].d   = newtuple;                               //
                A[i].d.m = -4294967296.0;                          //
                A[i].d.i = 0;                                      //
                A[i].d.j = 0;                                      //
                A[i].d.k = i;                                      //
            }
            // delete scratch space B
            arraysize = 2 * arraysize;                                                    // update size of array
            return;
        }