]> granicus.if.org Git - graphviz/commitdiff
remove manual memory management of dists in mingle
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 3 Jan 2021 18:26:57 +0000 (10:26 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 14 Feb 2021 03:14:13 +0000 (19:14 -0800)
Related to #1832.

lib/mingle/nearest_neighbor_graph_ann.cpp

index c6e6d7f9f86a406e2c16173f482c466feb3cc11e..173d177f1e407eff8b8401f535b5079d60aa6d53 100644 (file)
@@ -88,7 +88,6 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x,
   */
 
   ANNpointArray                dataPts;                                // data points
-  ANNdistArray         dists;                                  // near neighbor distances
   ANNkd_tree*                  kdTree;                                 // search structure
   
   double *xx;
@@ -103,7 +102,7 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x,
 
   dataPts = annAllocPts(nPts, dim);                    // allocate data points
   std::vector<ANNidx> nnIdx(k);                                                // allocate near neighbor indices
-  dists = new ANNdist[k];                                              // allocate near neighbor dists
+  std::vector<ANNdist> dists(k);                                       // allocate near neighbor dists
 
   for (int i = 0; i < nPts; i++){
     xx =  dataPts[i];
@@ -122,7 +121,7 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x,
                       dataPts[ip],                                             // query point
                       k,                                                               // number of near neighbors
                       nnIdx.data(),                                            // nearest neighbors (returned)
-                      dists,                                                   // distance (returned)
+                      dists.data(),                                            // distance (returned)
                       eps);                                                    // error bound
 
     for (int i = 0; i < k; i++) {                      // print summary
@@ -150,7 +149,7 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x,
                       dataPts[ip],                                             // query point
                       k,                                                               // number of near neighbors
                       nnIdx.data(),                                            // nearest neighbors (returned)
-                      dists,                                                   // distance (returned)
+                      dists.data(),                                            // distance (returned)
                       eps);                                                    // error bound
       
     for (int i = 0; i < k; i++) {                      // print summary
@@ -162,8 +161,7 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x,
     }
   }
     
-  delete [] dists;                                                     // clean things up
-  delete kdTree;
+  delete kdTree;                                                       // clean things up
     
   *nz0 = nz;