From: Matthew Fernandez Date: Thu, 15 Sep 2022 01:01:23 +0000 (-0700) Subject: sparse Dijkstra_internal: use cgraph wrappers for allocation X-Git-Tag: 6.0.2~35^2~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cbdc77baae052c4f6e6670e1727dd39365ff092;p=graphviz sparse Dijkstra_internal: use cgraph wrappers for allocation The lib/cgraph/alloc.h wrappers are similar to the older lib/common/memory.h wrappers except (1) they are header-only and (2) they live in a directory (cgraph) that is at the root of the dependency tree. The long term plan is to replace all use of lib/common/memory.h with lib/cgraph/alloc.h. --- diff --git a/lib/sparse/SparseMatrix.c b/lib/sparse/SparseMatrix.c index cd984f1c7..159ec4e96 100644 --- a/lib/sparse/SparseMatrix.c +++ b/lib/sparse/SparseMatrix.c @@ -1915,7 +1915,7 @@ static int Dijkstra_internal(SparseMatrix A, int root, double *dist, int *nlist, switch (A->type){ case MATRIX_TYPE_COMPLEX: aa = (double*) A->a; - a = MALLOC(sizeof(double)*((size_t)(A->nz))); + a = gv_calloc((size_t)A->nz, sizeof(double)); for (i = 0; i < A->nz; i++) a[i] = aa[i*2]; break; case MATRIX_TYPE_REAL: @@ -1923,18 +1923,18 @@ static int Dijkstra_internal(SparseMatrix A, int root, double *dist, int *nlist, break; case MATRIX_TYPE_INTEGER: ai = (int*) A->a; - a = MALLOC(sizeof(double)*((size_t)(A->nz))); + a = gv_calloc((size_t)A->nz, sizeof(double)); for (i = 0; i < A->nz; i++) a[i] = (double) ai[i]; break; case MATRIX_TYPE_PATTERN: - a = MALLOC(sizeof(double)*((size_t)A->nz)); + a = gv_calloc((size_t)A->nz, sizeof(double)); for (i = 0; i < A->nz; i++) a[i] = 1.; break; default: assert(0);/* no such matrix type */ } - heap_ids = MALLOC(sizeof(int)*((size_t)m)); + heap_ids = gv_calloc((size_t)m, sizeof(int)); for (i = 0; i < m; i++) { dist[i] = -1; heap_ids[i] = UNVISITED; @@ -1944,7 +1944,7 @@ static int Dijkstra_internal(SparseMatrix A, int root, double *dist, int *nlist, assert(h); /* add root as the first item in the heap */ - ndata = MALLOC(sizeof(struct nodedata_struct)); + ndata = gv_alloc(sizeof(struct nodedata_struct)); ndata->dist = 0; ndata->id = root; heap_ids[root] = BinaryHeap_insert(h, ndata); @@ -1964,7 +1964,7 @@ static int Dijkstra_internal(SparseMatrix A, int root, double *dist, int *nlist, if (jj == i || heap_id == FINISHED || (mask && mask[jj] < 0)) continue; if (heap_id == UNVISITED){ - ndata = MALLOC(sizeof(struct nodedata_struct)); + ndata = gv_alloc(sizeof(struct nodedata_struct)); ndata->dist = fabs(a[j]) + ndata_min->dist; ndata->id = jj; heap_ids[jj] = BinaryHeap_insert(h, ndata);