[GRASS-SVN] r59044 - grass/trunk/raster/r.li/r.li.daemon

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Feb 14 05:04:50 PST 2014


Author: mmetz
Date: 2014-02-14 05:04:50 -0800 (Fri, 14 Feb 2014)
New Revision: 59044

Modified:
   grass/trunk/raster/r.li/r.li.daemon/avl.c
   grass/trunk/raster/r.li/r.li.daemon/avlID.c
   grass/trunk/raster/r.li/r.li.daemon/avlID.h
Log:
r.li.daemon: add avlID_destroy

Modified: grass/trunk/raster/r.li/r.li.daemon/avl.c
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/avl.c	2014-02-14 10:40:28 UTC (rev 59043)
+++ grass/trunk/raster/r.li/r.li.daemon/avl.c	2014-02-14 13:04:50 UTC (rev 59044)
@@ -81,7 +81,6 @@
 	    save->right_child = it;
 	}
     }
-    
 }
 
 long howManyCell(const avl_tree root, const generic_cell k)

Modified: grass/trunk/raster/r.li/r.li.daemon/avlID.c
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/avlID.c	2014-02-14 10:40:28 UTC (rev 59043)
+++ grass/trunk/raster/r.li/r.li.daemon/avlID.c	2014-02-14 13:04:50 UTC (rev 59044)
@@ -49,7 +49,32 @@
     return root;
 }
 
+void avlID_destroy(avlID_tree root)
+{
+    struct avlID_node *it;
+    struct avlID_node *save = root;
 
+    /*
+    Rotate away the left links so that
+    we can treat this like the destruction
+    of a linked list
+    */
+    while((it = save) != NULL) {
+	if (it->left_child == NULL) {
+	    /* No left links, just kill the node and move on */
+	    save = it->right_child;
+	    G_free(it);
+	    it = NULL;
+	}
+	else {
+	    /* Rotate away the left link and check again */
+	    save = it->left_child;
+	    it->left_child = save->right_child;
+	    save->right_child = it;
+	}
+    }
+}
+
 long howManyID(const avlID_tree root, const long k)
 {
     avlID_node *nodo = NULL;

Modified: grass/trunk/raster/r.li/r.li.daemon/avlID.h
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/avlID.h	2014-02-14 10:40:28 UTC (rev 59043)
+++ grass/trunk/raster/r.li/r.li.daemon/avlID.h	2014-02-14 13:04:50 UTC (rev 59044)
@@ -29,6 +29,7 @@
 
 /* prototype of functions */
 avlID_tree avlID_make(const long k, const long n);
+void avlID_destroy(avlID_tree root);
 avlID_node *avlID_find(const avlID_tree root, const long k);
 int avlID_add(avlID_tree * root, const long k, const long n);
 long avlID_to_array(avlID_node * root, long i, avlID_table * a);



More information about the grass-commit mailing list