/* free the memory used by the vetting structure */ void mtsFreeWork (vetting_t ** w) { vetting_t *work = (*w); if (work->desired.X != -SPECIAL || work->desired.Y != -SPECIAL) { heap_free (work->untested.h, free); heap_destroy (&work->untested.h); heap_free (work->no_fix.h, free); heap_destroy (&work->no_fix.h); heap_free (work->no_hi.h, free); heap_destroy (&work->no_hi.h); heap_free (work->hi_candidate.h, free); heap_destroy (&work->hi_candidate.h); } else { while (!vector_is_empty (work->untested.v)) free (vector_remove_last (work->untested.v)); vector_destroy (&work->untested.v); while (!vector_is_empty (work->no_fix.v)) free (vector_remove_last (work->no_fix.v)); vector_destroy (&work->no_fix.v); while (!vector_is_empty (work->no_hi.v)) free (vector_remove_last (work->no_hi.v)); vector_destroy (&work->no_hi.v); while (!vector_is_empty (work->hi_candidate.v)) free (vector_remove_last (work->hi_candidate.v)); vector_destroy (&work->hi_candidate.v); } free (work); (*w) = NULL; }
/* qloop takes a vector (or heap) of regions to check (checking) if they don't intersect * anything. If a region does intersect something, it is broken into * pieces that don't intersect that thing (if possible) which are * put back into the vector/heap of regions to check. * qloop returns false when it finds the first empty region * it returns true if it has exhausted the region vector/heap and never * found an empty area. */ static void qloop (struct query_closure *qc, rtree_t * tree, heap_or_vector res, bool is_vec) { BoxType *cbox; #ifndef NDEBUG int n; #endif while (!(qc->desired ? heap_is_empty (qc->checking.h) : vector_is_empty (qc->checking.v))) { cbox = qc->desired ? (BoxTypePtr)heap_remove_smallest (qc->checking.h) : (BoxTypePtr)vector_remove_last (qc->checking.v); if (setjmp (qc->env) == 0) { assert (box_is_good (cbox)); qc->cbox = cbox; #ifndef NDEBUG n = #endif r_search (tree, cbox, NULL, query_one, qc); assert (n == 0); /* nothing intersected with this tree, put it in the result vector */ if (is_vec) vector_append (res.v, cbox); else { if (qc->desired) heap_append (res.h, qc->desired, cbox); else vector_append (res.v, cbox); } return; /* found one - perhaps one answer is good enough */ } } }
struct _attr_ret_ _attribute_add_children_(container *attributes, container *attr_query, container *hide, container *A, int container_id) { int i, j; container *list_items = vector_container( ptr_container() ); iterator it_m1 = map_begin(attributes); int has_selected_child = 0; for (; it_m1.valid; it_m1=map_next(it_m1)) { vector_pushback(attr_query, (char*)map_key(it_m1).ptr); int is_hidden = 0; for (i=0; i<vector_size(hide) && !is_hidden; i++) { container *hide_elem = vector_get(hide, i).C; for (j=0; j<vector_size(hide_elem); j++) { if (strcasecmp(vector_get(attr_query,j).ptr, vector_get(hide_elem,j).ptr)) break; } if (j>=vector_size(hide_elem)) is_hidden = 1; } if (is_hidden) { vector_remove_last(attr_query); continue; } struct _attr_tree_ *this_item = _attribute_tree_malloc_(); int val = _attribute_is_selected_(A, attr_query, container_id); if (val>=0) this_item->selected = val; if (map_size(pair(map_val(it_m1)).first.ptr) > 0) { struct _attr_ret_ ret = _attribute_add_children_(pair(map_val(it_m1)).first.ptr, attr_query, hide, A, container_id); if (ret.selected_descendant) { this_item->selected_descendant = 1; has_selected_child = 1; } this_item->children = ret.C; this_item->query_param = vector_container( string_container() ); for (j=0; j<vector_size(attr_query); j++) vector_pushback(this_item->query_param, vector_get(attr_query, j).ptr); //this_item->name = ; this_item->count = pair(map_val(it_m1)).second.ptr; } else { this_item->query_param = vector_container( string_container() ); for (j=0; j<vector_size(attr_query); j++) vector_pushback(this_item->query_param, vector_get(attr_query, j).ptr); //this_item->name = ; this_item->count = pair(map_val(it_m1)).second.ptr; } vector_remove_last(attr_query); if (this_item->name == NULL && this_item->query_param == NULL && this_item->count == NULL && this_item->children == NULL) { free(this_item); } else { vector_pushback(list_items, this_item); if (this_item->selected >= 0) has_selected_child = 1; } } struct _attr_ret_ ret; ret.C = list_items; ret.selected_descendant = has_selected_child; return ret; }