1 /* Apache 2.0 INS-AMU 2015 */
9 static int compare_int(const void *a
, const void *b
)
11 if ( *(int*) a
< *(int*) b
) return -1;
12 if ( *(int*) a
== *(int*) b
) return 0;
13 else /* a > b */ return 1;
16 int sk_util_fill_gauss(rk_state
*rng
, int nx
, double *x
)
26 int sk_util_uniqi(const int n
, const int *ints
, int *nuniq
, int **uints
)
32 /* sort copy of input vector */
33 ints_copy
= (int*) malloc(sizeof(int) * n
);
34 memcpy(ints_copy
, ints
, n
*sizeof(int));
38 qsort(ints_copy
, n
, sizeof(int), compare_int
);
42 for (i
=0; i
<(n
-1); i
++)
43 if (ints_copy
[i
] != ints_copy
[i
+1])
46 *uints
= (int*) malloc (sizeof(int) * *nuniq
);
48 /* copy unique into output array */
50 (*uints
)[j
++] = ints_copy
[0];
51 for (i
=0; i
<(n
-1); i
++)
52 if (ints_copy
[i
] != ints_copy
[i
+1])
53 (*uints
)[j
++] = ints_copy
[i
+1];