Ejemplo n.º 1
0
        private static bool kl_init(bilist *****bucket_ptrs, /* space for multiple bucket sorts */
                                    bilist ***listspace,     /* space for all elements of linked lists */
                                    int ***dvals,            /* change in cross edges for each move */
                                    int ***tops,             /* top dval for each type of move */
                                    int nvtxs,               /* number of vertices in the graph */
                                    int nsets,               /* number of sets created at each step */
                                    int maxchange            /* maximum change by moving a vertex */
                                    )
        {
            bilist * spacel; /* space for all listspace entries */
            bilist **spaceb; /* space for all buckets entries */
            int      sizeb;  /* size of set of buckets */
            int      sizel;  /* size of set of pointers for all vertices */
            int      i, j;   /* loop counters */

            /* Allocate appropriate data structures for buckets, and listspace. */

            *bucket_ptrs = (bilist ****)array_alloc_2D_ret <IntPtr>(nsets, nsets, sizeof(bilist *));

            *dvals = (int **)array_alloc_2D_ret <int>(nvtxs + 1, nsets - 1, sizeof(int));

            *tops = (int **)array_alloc_2D_ret <int>(nsets, nsets, sizeof(int));

            /* By using '-1' in the next line, I save space, but I need to */
            /* be careful to get the right element in listspace each time. */
            *listspace = (bilist **)Marshal.AllocHGlobal((nsets - 1) * sizeof(bilist *));

            sizeb  = (2 * maxchange + 1) * sizeof(bilist *);
            sizel  = (nvtxs + 1) * sizeof(bilist);
            spacel = (bilist *)Marshal.AllocHGlobal((nsets - 1) * sizel);
            spaceb = (bilist **)Marshal.AllocHGlobal(nsets * (nsets - 1) * sizeb);

            if (*bucket_ptrs == null || *dvals == null || *tops == null || *listspace == null ||
                spacel == null || spaceb == null)
            {
                Marshal.FreeHGlobal((IntPtr)spacel);
                Marshal.FreeHGlobal((IntPtr)spaceb);
                return(true);
            }

            for (i = 0; i < nsets; i++)
            {
                if (i != nsets - 1)
                {
                    (*listspace)[i] = spacel;
                    spacel         += nvtxs + 1;
                }

                for (j = 0; j < nsets; j++)
                {
                    if (i != j)
                    {
                        (*bucket_ptrs)[i][j] = spaceb;
                        spaceb += 2 * maxchange + 1;
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static bool klv_init(bilist ***lbucket_ptr, /* space for left bucket sorts */
                                    bilist ***rbucket_ptr, /* space for right bucket sorts */
                                    bilist **llistspace,   /* space for elements of linked lists */
                                    bilist **rlistspace,   /* space for elements of linked lists */
                                    int **ldvals,          /* change in separator for left moves */
                                    int **rdvals,          /* change in separator for right moves */
                                    int nvtxs,             /* number of vertices in the graph */
                                    int maxchange          /* maximum change by moving a vertex */
                                    )
        {
            int sizeb; /* size of set of buckets */
            int sizel; /* size of set of pointers for all vertices */

            /* Allocate appropriate data structures for buckets, and listspace. */

            sizeb = (2 * maxchange + 1) * sizeof(bilist *);
            *lbucket_ptr = (bilist **)Marshal.AllocHGlobal(sizeb);
            *rbucket_ptr = (bilist **)Marshal.AllocHGlobal(sizeb);

            *ldvals = (int *)Marshal.AllocHGlobal((nvtxs + 1) * sizeof(int));
            *rdvals = (int *)Marshal.AllocHGlobal((nvtxs + 1) * sizeof(int));

            sizel = (nvtxs + 1) * sizeof(bilist);
            *llistspace = (bilist *)Marshal.AllocHGlobal(sizel);
            *rlistspace = (bilist *)Marshal.AllocHGlobal(sizel);

            return(*lbucket_ptr == null || *rbucket_ptr == null || *ldvals == null || *rdvals == null ||
                   *llistspace == null || *rlistspace == null);
        }