From: Matthew Fernandez Date: Wed, 23 Jun 2021 03:35:33 +0000 (-0700) Subject: remove ascending parameter from vector_ordering X-Git-Tag: 2.48.0~39^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc83f07736d8914754baec12076b8dd533b3e02d;p=graphviz remove ascending parameter from vector_ordering All calls to this use ascending, so having this configurable was adding unnecessary maintenance burden. --- diff --git a/cmd/gvmap/country_graph_coloring.c b/cmd/gvmap/country_graph_coloring.c index e60bee50c..acffdf3d2 100644 --- a/cmd/gvmap/country_graph_coloring.c +++ b/cmd/gvmap/country_graph_coloring.c @@ -308,7 +308,7 @@ static void country_graph_coloring_internal(int seed, SparseMatrix A, int **p, r power_method(L, L->n, 1, seed, maxit, tol, &v, &eigv); } - vector_ordering(n, v, p, TRUE); + vector_ordering(n, v, p); if (Verbose) fprintf(stderr, "cpu time for spectral ordering (before greedy) = %f\n", (real) (clock() - start)/(CLOCKS_PER_SEC)); diff --git a/lib/sparse/general.c b/lib/sparse/general.c index a31415cad..c36ab37fe 100644 --- a/lib/sparse/general.c +++ b/lib/sparse/general.c @@ -19,7 +19,7 @@ real vector_median(int n, real *x){ /* find the median value in a list of real */ int *p = NULL; real res; - vector_ordering(n, x, &p, TRUE); + vector_ordering(n, x, &p); if ((n/2)*2 == n){ res = 0.5*(x[p[n/2-1]] + x[p[n/2]]); @@ -35,7 +35,7 @@ real vector_percentile(int n, real *x, real y){ */ int *p = NULL, i; real res; - vector_ordering(n, x, &p, TRUE); + vector_ordering(n, x, &p); y = MIN(y, 1); @@ -203,16 +203,9 @@ static int comp_ascend_int(const void *s1, const void *s2){ return 0; } - -void vector_ordering(int n, real *v, int **p, int ascending){ - /* give the position of the lagest, second largest etc in vector v if ascending = FALSE - - or - - give the position of the smallest, second smallest etc in vector v if ascending = TRUE. +void vector_ordering(int n, real *v, int **p){ + /* give the position of the smallest, second smallest etc in vector v. results in p. If *p == NULL, p is assigned. - - ascending: TRUE if v[p] is from small to large. */ real *u; @@ -226,11 +219,7 @@ void vector_ordering(int n, real *v, int **p, int ascending){ u[2*i] = v[i]; } - if (ascending){ - qsort(u, n, sizeof(real)*2, comp_ascend); - } else { - qsort(u, n, sizeof(real)*2, comp_descend); - } + qsort(u, n, sizeof(real)*2, comp_ascend); for (i = 0; i < n; i++) (*p)[i] = (int) u[2*i+1]; FREE(u); diff --git a/lib/sparse/general.h b/lib/sparse/general.h index a6092ce2b..006487d16 100644 --- a/lib/sparse/general.h +++ b/lib/sparse/general.h @@ -104,7 +104,7 @@ void vector_float_take(int n, float *v, int m, int *p, float **u); give the position of the smallest, second smallest etc in vector v if ascending = TRUE. results in p. If *p == NULL, p is assigned. */ -void vector_ordering(int n, real *v, int **p, int ascending); +void vector_ordering(int n, real *v, int **p); void vector_sort_real(int n, real *v, int ascending); void vector_sort_int(int n, int *v, int ascending); real vector_median(int n, real *x);