From fac1ad7fb3e1a4537735daf265d6540536a8ef5d Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 15 Jan 2022 14:11:29 -0800 Subject: [PATCH] Agglomerative_Ink_Bundling: remove 'inks' manual memory management --- lib/mingle/agglomerative_bundling.cpp | 11 +++++------ lib/mingle/agglomerative_bundling.h | 4 +++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/mingle/agglomerative_bundling.cpp b/lib/mingle/agglomerative_bundling.cpp index f6e21c6b8..d09917dd9 100644 --- a/lib/mingle/agglomerative_bundling.cpp +++ b/lib/mingle/agglomerative_bundling.cpp @@ -45,15 +45,14 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_init(SparseMatrix A grid->R0 = NULL; grid->R = NULL; grid->next = NULL; - grid->inks = (double*)MALLOC(sizeof(double)*(A->m)); grid->edges = edges; grid->delete_top_level_A = 0; grid->total_ink = -1; if (level == 0){ double total_ink = 0; for (i = 0; i < n; i++) { - (grid->inks)[i] = ink1(edges[i]); - total_ink += (grid->inks)[i]; + grid->inks.push_back(ink1(edges[i])); + total_ink += grid->inks[i]; } grid->total_ink = total_ink; } @@ -73,7 +72,6 @@ static void Agglomerative_Ink_Bundling_delete(Agglomerative_Ink_Bundling grid){ /* on level 0, R0 = NULL, on level 1, R0 = R */ if (grid->level > 1) SparseMatrix_delete(grid->R0); SparseMatrix_delete(grid->R); - free(grid->inks); Agglomerative_Ink_Bundling_delete(grid->next); free(grid); @@ -86,7 +84,8 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera int *ia = A->ia, *ja = A->ja; int i, j, k, jj, jc, jmax, ni, nj, npicks; pedge *edges = grid->edges; - double *inks = grid->inks, *cinks, inki, inkj; + const std::vector &inks = grid->inks; + double inki, inkj; double gain, maxgain, minink, total_gain = 0; int *ip = NULL, *jp = NULL, ie; std::vector> cedges;/* a table listing the content of bundled edges in the coarsen grid. @@ -96,7 +95,7 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera if (Verbose > 1) fprintf(stderr,"level ===================== %d, n = %d\n",grid->level, n); cedges.resize(n); - cinks = (double*)MALLOC(sizeof(double)*n); + std::vector cinks(n, 0.0); if (grid->level > 0){ ip = grid->R0->ia; diff --git a/lib/mingle/agglomerative_bundling.h b/lib/mingle/agglomerative_bundling.h index aa347bde0..c6364137f 100644 --- a/lib/mingle/agglomerative_bundling.h +++ b/lib/mingle/agglomerative_bundling.h @@ -10,6 +10,8 @@ #pragma once +#include + typedef struct Agglomerative_Ink_Bundling_struct *Agglomerative_Ink_Bundling; struct Agglomerative_Ink_Bundling_struct { @@ -21,7 +23,7 @@ struct Agglomerative_Ink_Bundling_struct { the nodes on the finest grid corresponding to the coarsest node 1, etc */ SparseMatrix R;/* striction mtrix from level to level + 1*/ Agglomerative_Ink_Bundling next; - double *inks; /* amount of ink needed to draw this edge/bundle. Dimension n. */ + std::vector inks; /* amount of ink needed to draw this edge/bundle. Dimension n. */ double total_ink; /* amount of ink needed to draw this edge/bundle. Dimension n. */ pedge* edges; /* the original edge info. This does not vary level to level and is of dimenion n0, where n0 is the number of original edges */ int delete_top_level_A;/*whether the top level matrix should be deleted on garbage collecting the grid */ -- 2.40.0