Debian Codegraph @

packages/seacas/libraries/chaco/klspiff/kl_init.c

raw
1 /*
2 * Copyright(C) 1999-2020, 2023 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8
9 #include "smalloc.h" // for smalloc_ret
10 #include "structs.h" // for bilist
11 #include <stddef.h> // for size_t
12 #include <stdio.h> // for NULL
13
14 int kl_init(struct bilist *****bucket_ptrs, /* space for multiple bucket sorts */
15 struct bilist ***listspace, /* space for all elements of linked lists */
16 int ***dvals, /* change in cross edges for each move */
17 int ***tops, /* top dval for each type of move */
18 int nvtxs, /* number of vertices in the graph */
19 int nsets, /* number of sets created at each step */
20 int maxchange /* maximum change by moving a vertex */
21 )
22 {
23 struct bilist *spacel; /* space for all listspace entries */
24 struct bilist **spaceb; /* space for all buckets entries */
25 size_t sizeb; /* size of set of buckets */
26 size_t sizel; /* size of set of pointers for all vertices */
27 int i, j; /* loop counters */
28
29 /* Allocate appropriate data structures for buckets, and listspace. */
30
31 *bucket_ptrs = (struct bilist ****)array_alloc_2D_ret(nsets, nsets, sizeof(struct bilist *));
32
33 *dvals = (int **)array_alloc_2D_ret(nvtxs + 1, nsets - 1, sizeof(int));
34
35 *tops = (int **)array_alloc_2D_ret(nsets, nsets, sizeof(int));
36
37 /* By using '-1' in the next line, I save space, but I need to */
38 /* be careful to get the right element in listspace each time. */
39 *listspace = smalloc_ret((nsets - 1) * sizeof(struct bilist *));
40
41 sizeb = (2 * maxchange + 1) * sizeof(struct bilist *);
42 sizel = (nvtxs + 1) * sizeof(struct bilist);
43 spacel = smalloc_ret((nsets - 1) * sizel);
44 spaceb = smalloc_ret(nsets * (nsets - 1) * sizeb);
45
46 if (*bucket_ptrs == NULL || *dvals == NULL || *tops == NULL || *listspace == NULL ||
47 spacel == NULL || spaceb == NULL) {
48 sfree(spacel);
49 sfree(spaceb);
50 return (1);
51 }
52
53 for (i = 0; i < nsets; i++) {
54 if (i != nsets - 1) {
55 (*listspace)[i] = spacel;
56 spacel += nvtxs + 1;
57 }
58
59 for (j = 0; j < nsets; j++) {
60 if (i != j) {
61 (*bucket_ptrs)[i][j] = spaceb;
62 spaceb += 2 * maxchange + 1;
63 }
64 }
65 }
66
67 return (0);
68 }