[GRASS-SVN] r62279 - in grass/branches/releasebranch_7_0/raster/r.li: r.li.daemon r.li.dominance r.li.pielou r.li.renyi r.li.shannon r.li.simpson

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 17 08:55:35 PDT 2014


Author: wenzeslaus
Date: 2014-10-17 08:55:35 -0700 (Fri, 17 Oct 2014)
New Revision: 62279

Modified:
   grass/branches/releasebranch_7_0/raster/r.li/r.li.daemon/avl.c
   grass/branches/releasebranch_7_0/raster/r.li/r.li.daemon/avl.h
   grass/branches/releasebranch_7_0/raster/r.li/r.li.dominance/dominance.c
   grass/branches/releasebranch_7_0/raster/r.li/r.li.pielou/pielou.c
   grass/branches/releasebranch_7_0/raster/r.li/r.li.renyi/renyi.c
   grass/branches/releasebranch_7_0/raster/r.li/r.li.shannon/shannon.c
   grass/branches/releasebranch_7_0/raster/r.li/r.li.simpson/simpson.c
Log:
fix and improve memory handling by better allocations and proper type use (backport of r61812)

Modified: grass/branches/releasebranch_7_0/raster/r.li/r.li.daemon/avl.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.li/r.li.daemon/avl.c	2014-10-17 15:53:11 UTC (rev 62278)
+++ grass/branches/releasebranch_7_0/raster/r.li/r.li.daemon/avl.c	2014-10-17 15:55:35 UTC (rev 62279)
@@ -193,7 +193,7 @@
 
 
 
-long avl_to_array(avl_node * root, long i, AVL_table * a)
+long avl_to_array(avl_node * root, long i, AVL_table a)
 {
 
     if (root != NULL) {
@@ -201,9 +201,8 @@
 	if (a == NULL)
 	    G_fatal_error("avl, avl_to_array: null value");
 	else {
-	    a[i] = G_malloc(sizeof(AVL_tableRow));
-	    a[i]->k = root->key;
-	    a[i]->tot = root->counter;
+	    a[i].k = root->key;
+	    a[i].tot = root->counter;
 	    i++;
 	    i = avl_to_array(root->right_child, i, a);
 	}

Modified: grass/branches/releasebranch_7_0/raster/r.li/r.li.daemon/avl.h
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.li/r.li.daemon/avl.h	2014-10-17 15:53:11 UTC (rev 62278)
+++ grass/branches/releasebranch_7_0/raster/r.li/r.li.daemon/avl.h	2014-10-17 15:55:35 UTC (rev 62279)
@@ -37,7 +37,7 @@
 void avl_destroy(avl_tree root);
 avl_node *avl_find(const avl_tree root, const generic_cell k);
 int avl_add(avl_tree * root, const generic_cell k, const long n);
-long avl_to_array(avl_node * root, long i, AVL_table * a);
+long avl_to_array(avl_node * root, long i, AVL_table a);
 long howManyCell(const avl_tree root, const generic_cell k);
 
 

Modified: grass/branches/releasebranch_7_0/raster/r.li/r.li.dominance/dominance.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.li/r.li.dominance/dominance.c	2014-10-17 15:53:11 UTC (rev 62278)
+++ grass/branches/releasebranch_7_0/raster/r.li/r.li.dominance/dominance.c	2014-10-17 15:55:35 UTC (rev 62279)
@@ -123,7 +123,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -269,7 +269,7 @@
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -310,7 +310,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -456,7 +456,7 @@
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -497,7 +497,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -643,7 +643,7 @@
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;

Modified: grass/branches/releasebranch_7_0/raster/r.li/r.li.pielou/pielou.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.li/r.li.pielou/pielou.c	2014-10-17 15:53:11 UTC (rev 62278)
+++ grass/branches/releasebranch_7_0/raster/r.li/r.li.pielou/pielou.c	2014-10-17 15:55:35 UTC (rev 62279)
@@ -123,7 +123,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -269,7 +269,7 @@
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -310,7 +310,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -456,7 +456,7 @@
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -497,7 +497,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -643,7 +643,7 @@
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;

Modified: grass/branches/releasebranch_7_0/raster/r.li/r.li.renyi/renyi.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.li/r.li.renyi/renyi.c	2014-10-17 15:53:11 UTC (rev 62278)
+++ grass/branches/releasebranch_7_0/raster/r.li/r.li.renyi/renyi.c	2014-10-17 15:55:35 UTC (rev 62279)
@@ -147,7 +147,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -297,7 +297,7 @@
 	sum = 0;
 	sum2 = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    pi = t / area;
 	    sum += pow(pi, alpha);
 	    sum2 += pi;
@@ -348,7 +348,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -498,7 +498,7 @@
 	sum = 0;
 	sum2 = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    pi = t / area;
 	    sum += pow(pi, alpha);
 	    sum += pi;
@@ -549,7 +549,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -699,7 +699,7 @@
 	sum = 0;
 	sum2 = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    pi = t / area;
 	    sum += pow(pi, alpha);
 	    sum2 += pi;

Modified: grass/branches/releasebranch_7_0/raster/r.li/r.li.shannon/shannon.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.li/r.li.shannon/shannon.c	2014-10-17 15:53:11 UTC (rev 62278)
+++ grass/branches/releasebranch_7_0/raster/r.li/r.li.shannon/shannon.c	2014-10-17 15:55:35 UTC (rev 62279)
@@ -123,7 +123,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -269,7 +269,7 @@
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -310,7 +310,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -456,7 +456,7 @@
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;
@@ -497,7 +497,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -643,7 +643,7 @@
 	/* calculate shannon */
 	shannon = 0;
 	for (i = 0; i < m; i++) {
-	    t = array[i]->tot;
+	    t = array[i].tot;
 	    perc = t / area;
 	    logarithm = log(perc);
 	    shannon += perc * logarithm;

Modified: grass/branches/releasebranch_7_0/raster/r.li/r.li.simpson/simpson.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.li/r.li.simpson/simpson.c	2014-10-17 15:53:11 UTC (rev 62278)
+++ grass/branches/releasebranch_7_0/raster/r.li/r.li.simpson/simpson.c	2014-10-17 15:55:35 UTC (rev 62279)
@@ -123,7 +123,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = CELL_TYPE;
@@ -269,7 +269,7 @@
 	/* calculate simpson */
 	simpson = 0;
 	for (i = 0; i < m; i++) {
-	    t = (double)(array[i]->tot);
+	    t = (double)(array[i].tot);
 	    p = t / area;
 	    simpson += (p * p);
 	}
@@ -309,7 +309,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = DCELL_TYPE;
@@ -455,7 +455,7 @@
 	/* calculate simpson */
 	simpson = 0;
 	for (i = 0; i < m; i++) {
-	    t = (double)(array[i]->tot);
+	    t = (double)(array[i].tot);
 	    p = t / area;
 	    simpson += (p * p);
 	}
@@ -495,7 +495,7 @@
     long area = 0;
 
     avl_tree albero = NULL;
-    AVL_table *array;
+    AVL_table array;
     generic_cell uc;
 
     uc.t = FCELL_TYPE;
@@ -641,7 +641,7 @@
 	/* calculate simpson */
 	simpson = 0;
 	for (i = 0; i < m; i++) {
-	    t = (double)(array[i]->tot);
+	    t = (double)(array[i].tot);
 	    p = t / area;
 	    simpson += (p * p);
 	}



More information about the grass-commit mailing list