Debian Codegraph @

packages/seacas/libraries/chaco/bpmatch/sorts2d.c

raw
1 /*
2 * Copyright(C) 1999-2020 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 "params.h" // for MAXSETS
10 #include "smalloc.h" // for smalloc, sfree
11
12 void sorts2d(
13 /* Sort the lists needed to find the splitter. */
14 double *vals[4][MAXSETS], /* lists of values to sort */
15 int *indices[4][MAXSETS], /* indices of sorted lists */
16 int nvtxs /* number of vertices */
17 )
18 {
19 int *space; /* space for mergesort routine */
20 int *temp[4]; /* place holders for indices */
21 int nlists = 4; /* number of directions to sort */
22 int i; /* loop counter */
23
24 void ch_mergesort(double *vals, int nvals, int *indices, int *space);
25
26 space = smalloc(nvtxs * sizeof(int));
27
28 for (i = 0; i < nlists; i++) {
29 temp[i] = smalloc(nvtxs * sizeof(int));
30 }
31
32 ch_mergesort(vals[0][1], nvtxs, temp[0], space);
33 ch_mergesort(vals[0][2], nvtxs, temp[1], space);
34 ch_mergesort(vals[0][3], nvtxs, temp[2], space);
35 ch_mergesort(vals[1][2], nvtxs, temp[3], space);
36
37 sfree(space);
38
39 indices[0][1] = indices[1][0] = indices[2][3] = indices[3][2] = temp[0];
40 indices[0][2] = indices[2][0] = indices[1][3] = indices[3][1] = temp[1];
41 indices[0][3] = indices[3][0] = temp[2];
42 indices[1][2] = indices[2][1] = temp[3];
43 }