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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 13 05:36:09 PST 2014


Author: mmetz
Date: 2014-02-13 05:36:09 -0800 (Thu, 13 Feb 2014)
New Revision: 59025

Modified:
   grass/trunk/raster/r.li/r.li.daemon/avl.c
   grass/trunk/raster/r.li/r.li.daemon/avl.h
Log:
r.li.daemon: add avl_destroy()

Modified: grass/trunk/raster/r.li/r.li.daemon/avl.c
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/avl.c	2014-02-13 13:35:30 UTC (rev 59024)
+++ grass/trunk/raster/r.li/r.li.daemon/avl.c	2014-02-13 13:36:09 UTC (rev 59025)
@@ -33,7 +33,7 @@
 void printAVL(avl_node * r);
 
 
-/* define function declsred in avl.h */
+/* define function declared in avl.h */
 
 avl_tree avl_make(const generic_cell k, const long n)
 {
@@ -57,7 +57,33 @@
     return root;
 }
 
+void avl_destroy(avl_tree root)
+{
+    struct avl_node *it;
+    struct avl_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 howManyCell(const avl_tree root, const generic_cell k)
 {
     avl_node *nodo = NULL;

Modified: grass/trunk/raster/r.li/r.li.daemon/avl.h
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/avl.h	2014-02-13 13:35:30 UTC (rev 59024)
+++ grass/trunk/raster/r.li/r.li.daemon/avl.h	2014-02-13 13:36:09 UTC (rev 59025)
@@ -34,6 +34,7 @@
 
 /* prototype of functions */
 avl_tree avl_make(const generic_cell k, const long n);
+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);



More information about the grass-commit mailing list