Commits

Kanwei Li committed ffdc397

Free tree iterator in clustertree after getting results

Comments (0)

Files changed (3)

lib/bx/intervals/cluster.pyx

     clusternode* clusternode_insert(clustertree *tree, clusternode *node, int start, int end, int id)
     clustertree* create_clustertree(int max_dist, int min_intervals)
     treeitr* clusteritr(clustertree *tree)
+    void freeclusteritr(treeitr *itr)
     void free_tree(clustertree *tree)
 
 cdef class ClusterTree:
 
             regions.append( (itr.node.start, itr.node.end, sorted(ids)) )
             itr = itr.next
+        freeclusteritr(itr)
         return regions
         
     def getlines(self):
             
             lines.extend(sorted(ids))
             itr = itr.next
+        freeclusteritr(itr)
         return lines
         
     return NULL;
 }
 
+/* Free iterator (tail recursive) */
+void freeclusteritr(treeitr *itr) {
+    treeitr *next;
+    if (itr == NULL) {
+        return;
+    }
+    
+    next = itr->next;
+    free(itr);
+    freeclusteritr(next);
+}
+
 /* Insert based on the start position of intervals */
 clusternode* clusternode_insert(clustertree *tree, clusternode *node, int start, int end, int id) {
     int oldstart;
 clusternode* clusternode_insert(clustertree *tree, clusternode *node, int start, int end, int id);
 clustertree* create_clustertree(int max_dist, int min_intervals);
 treeitr* clusteritr(clustertree *tree);
+void freeclusteritr(treeitr *itr);
 void free_tree(clustertree *tree);