void crm114__list_clear(SparseElementList *l) { SparseNode curr, next; int i; if (!l) { if (CRM114__MATR_DEBUG_MODE) { fprintf(stderr, "crm114__list_clear: null list.\n"); } return; } curr = l->head; i = 0; while (!null_node(curr)) { next = next_node(curr); if (!(l->last_addr)) { node_free(curr); } else { if (l->compact && ((void *)curr.compact < (void *)l || (void *)curr.compact >= l->last_addr)) { node_free(curr); } if (!(l->compact) && ((void *)curr.precise < (void *)l || (void *)curr.precise >= l->last_addr)) { node_free(curr); } } curr = next; i++; } l->head = make_null_node(l->compact); l->tail = make_null_node(l->compact); }
void test_llist_rm_first(void) { Llist list = NULL; Node arc1; Node arc2; node_alloc(&arc1); node_alloc(&arc2); arc1.score = 150; arc2.score = 151; /* See if trying to suppress an element of an empty list works */ CU_ASSERT_TRUE(llist_rm_first(&list)); /* Add something in order to suppress it later */ llist_add(arc1, &list); llist_add(arc2, &list); /* Suppress the first element of the list */ llist_rm_first(&list); /* See if the remaining list have arc2 has its first element */ CU_ASSERT_TRUE(node_is_equal(list->value, arc1)); /* See deleting an element returns 0 */ CU_ASSERT_FALSE(llist_rm_first(&list)); /* Confirm the list is now a NULL pointer */ CU_ASSERT_PTR_NULL(list); node_free(&arc1); node_free(&arc2); }
void node_free(struct node *n) { if(n != NULL) { node_free(n->left); node_free(n->right); free(n); } }
CTEST(node_serial_test, leaf_empty) { int ret = 0; int fd = ness_os_open(BRT_FILE, O_RDWR | O_CREAT, 0777); struct block *b = block_new(); struct hdr *hdr = (struct hdr*)xcalloc(1, sizeof(*hdr)); struct options *opts = options_new(); /* * dummy brt leaf */ uint64_t nid = 3; struct node *dummy_leaf = leaf_alloc_empty(nid); leaf_alloc_bsm(dummy_leaf); ret = serialize_node_to_disk(fd, b, dummy_leaf, hdr); ASSERT_TRUE(ret > 0); //free node_free(dummy_leaf); struct node *dummy_leaf1; ret = deserialize_node_from_disk(fd, b, nid, &dummy_leaf1, 0); ASSERT_TRUE(ret > 0); ASSERT_EQUAL(0, basement_count(dummy_leaf1->u.l.le->bsm)); //free node_free(dummy_leaf1); ness_os_close(fd); block_free(b); xfree(hdr); options_free(opts); xcheck_all_free(); }
static void free_row(TABLE_ROW *r) { struct Node *n = r->cells.l_head; while (list_isNode(n)) { TABLE_CELL *c = (TABLE_CELL *) n; n = n->n_succ; node_free(&c->node); } node_free(&r->node); }
/** * Destroy tree * * quadtree_free(quadtree_t *tree) * @return void */ void quadtree_free(quadtree_t *tree) { if (tree->key_free != NULL) { node_free(tree->root, tree->key_free); } else { node_free(tree->root, black_hole_); } free(tree); }
static int recreate_normal_tree(const zone_contents_t *z, zone_contents_t *out) { out->nodes = hattrie_dup(z->nodes, NULL); if (out->nodes == NULL) { return KNOT_ENOMEM; } // Insert APEX first. zone_node_t *apex_cpy = node_shallow_copy(z->apex, NULL); if (apex_cpy == NULL) { return KNOT_ENOMEM; } // Normal additions need apex ... so we need to insert directly. int ret = zone_tree_insert(out->nodes, apex_cpy); if (ret != KNOT_EOK) { node_free(&apex_cpy, NULL); return ret; } out->apex = apex_cpy; hattrie_iter_t *itt = hattrie_iter_begin(z->nodes, true); if (itt == NULL) { return KNOT_ENOMEM; } while (!hattrie_iter_finished(itt)) { const zone_node_t *to_cpy = (zone_node_t *)*hattrie_iter_val(itt); if (to_cpy == z->apex) { // Inserted already. hattrie_iter_next(itt); continue; } zone_node_t *to_add = node_shallow_copy(to_cpy, NULL); if (to_add == NULL) { hattrie_iter_free(itt); return KNOT_ENOMEM; } int ret = zone_contents_add_node(out, to_add, true); if (ret != KNOT_EOK) { node_free(&to_add, NULL); hattrie_iter_free(itt); return ret; } hattrie_iter_next(itt); } hattrie_iter_free(itt); hattrie_build_index(out->nodes); return KNOT_EOK; }
void node_free (struct node * n) { if (n == NULL) return; node_free (n->left); node_free (n->right); free (n->data); free (n); }
void crm114__list_remove_elt(SparseElementList *l, SparseNode toremove) { if (!l) { if (CRM114__MATR_DEBUG_MODE) { fprintf(stderr, "crm114__list_remove_elt: null list.\n"); } return; } if (null_node(toremove)) { return; } if (!null_node(prev_node(toremove))) { if (l->compact) { toremove.compact->prev->next = toremove.compact->next; } else { toremove.precise->prev->next = toremove.precise->next; } } else { if (l->compact) { l->head.compact = toremove.compact->next; } else { l->head.precise = toremove.precise->next; } } if (!null_node(next_node(toremove))) { if (l->compact) { toremove.compact->next->prev = toremove.compact->prev; } else { toremove.precise->next->prev = toremove.precise->prev; } } else { if (l->compact) { l->tail.compact = toremove.compact->prev; } else { l->tail.precise = toremove.precise->prev; } } if (l->compact) { if (!(l->last_addr) || (void *)toremove.compact < (void *)l || (void *)toremove.compact >= l->last_addr) { node_free(toremove); } } else { if (!(l->last_addr) || (void *)toremove.precise < (void *)l || (void *)toremove.precise >= l->last_addr) { node_free(toremove); } } }
HIDDEN void node_free(Node *node, bool deep) { if (node == pt_null) return; if (deep) { node_free(node->right, true); node_free(node->left, true); free(node->piece); } free(node); }
int main(int argc, char **argv) { opt_t *options; int rc = EXIT_FAILURE; options = opt_new(argc, argv); if (options->input) { if (!(yyin = fopen(options->input, "r"))) { int n = errno; log_error("cannot open input file '%s': %s\n", options->input, strerror(n)); goto end; } } if (yyparse() != 0) { log_error("could not parse DDL"); goto end; } if (node_create(file, NULL, options) != 0) { log_error("error creating HDF5 file"); } node_free(file); rc = EXIT_SUCCESS; end: if (options->input) { fclose(yyin); } opt_free(options); return rc; }
/* * Remove any duplicate schedules. We do this by sorting against ScheduleID * and then keeping the first one, which should match the order in STP above. * * This shouldn't be necessary if the underlying stream filtered correctly * but this is a second check, more so if like the stanox API we can't guarantee * uniqueness until streams support this (which may be some time). */ static void removeDuplicates(List *list) { // Sort into UID order list_sort(list, duplicateComparator); // Remove duplicates char *uid = NULL; int tiploc = 0; int seq = 0; Node *n = list_getHead(list); while (list_isNode(n)) { Node *next = list_getNext(n); struct ScheduleIndex *idx = n->value; if (!list_isHead(n) && strcmp(uid, idx->id->uid) == 0 && tiploc == idx->loc->tiploc && seq == idx->loc->tiplocseq ) { // This will remove & free n and the ScheduleIndex instance list_remove(n); node_free(n); } else { uid = idx->id->uid; tiploc = idx->loc->tiploc; seq = idx->loc->tiplocseq; } n = next; } }
void print_Node_info( struct DB *db, struct BTreeNode *node){ struct MyDB *myDB = ( struct MyDB *) db; printf("NODE INFO\n"); printf("offset -> %lu \n",node->offset); printf("n -> %lu \n",node->n); printf("isleaf -> %d \n",node->leaf); long i; for(i=0;i<node->n;i++){ printf("%li key is \"%s\", ",i,(char *)(node->keys[i]).data); printf("%li value is \"%s\"\n",i,(char *)(node->values[i]).data); } if(!node->leaf && node->n>0) { printf("\n-----------------MINI CHILDREN of %lu\n",node->offset); for(i=0;i< node->n +1;i++){ printf("child %li -> %lu\n",i,node->childs[i]); } } printf("\n-----------------FULL CHILDREN of %lu\n\n", node->offset); if(!node->leaf && node->n>0) { for(i=0;i< node->n +1;i++){ printf("\n|||||%li child is in %lu offset||||||\n",i,node->childs[i]); struct BTreeNode *c = node_disk_read(myDB, node->childs[i]); print_Node_info(( struct DB *)myDB, c); node_free(myDB,c); } } else printf("|||| no children :( ||||\n"); printf("\n-----------------ENDOFCHILDREN of %lu\n\n",node->offset); }
void remove_all(struct hash *hash, struct node *n) { struct tree *t; struct tree_node *h, *s; if (n->neededby->root || n->providedby->root) return; h = tree_first(n->provide->root); while (h) { s = tree_search_tree_node(h->n->providedby, n); tree_node_free(h->n->providedby, s); remove_all(hash, h->n); h = tree_next(h); } h = tree_first(n->need->root); while (h) { s = tree_search_tree_node(h->n->neededby, n); tree_node_free(h->n->neededby, s); remove_all(hash, h->n); h = tree_next(h); } t = hash->tbl[hash_index(n->name)]; s = tree_search_tree_node(t, n); tree_node_free(t, s); node_free(n); }
// do not call this if there is the possibility that items // are still being added to the queue. void queue_destroy(queue_ptr queue) { assert(NULL != queue); // empty the queue, calling the destroy function for the items void* node = NULL; while(queue_pop_nowait(queue, &node)) { if(NULL != queue->destroy_node) { queue->destroy_node(node); } } if(NULL != queue->lock) { enif_mutex_destroy(queue->lock); } if(NULL != queue->cond) { enif_cond_destroy(queue->cond); } memset(queue, 0, sizeof(struct queue)); node_free(queue); }
static int recreate_nsec3_tree(const zone_contents_t *z, zone_contents_t *out) { out->nsec3_nodes = hattrie_dup(z->nsec3_nodes, NULL); if (out->nsec3_nodes == NULL) { return KNOT_ENOMEM; } hattrie_iter_t *itt = hattrie_iter_begin(z->nsec3_nodes, false); if (itt == NULL) { return KNOT_ENOMEM; } while (!hattrie_iter_finished(itt)) { const zone_node_t *to_cpy = (zone_node_t *)*hattrie_iter_val(itt); zone_node_t *to_add = node_shallow_copy(to_cpy, NULL); if (to_add == NULL) { hattrie_iter_free(itt); return KNOT_ENOMEM; } int ret = zone_contents_add_nsec3_node(out, to_add); if (ret != KNOT_EOK) { hattrie_iter_free(itt); node_free(&to_add, NULL); return ret; } hattrie_iter_next(itt); } hattrie_iter_free(itt); hattrie_build_index(out->nsec3_nodes); return KNOT_EOK; }
static void free_nodedata (MateComponentUIXml *tree, MateComponentUIXmlData *data, gboolean do_overrides) { if (data) { if (data->overridden) { if (do_overrides) { GSList *l; for (l = data->overridden; l; l = l->next) node_free (tree, l->data); g_slist_free (data->overridden); } else /* * This indicates a serious error in the * overriding logic. */ g_warning ("Leaking overridden nodes"); } if (tree->data_free) tree->data_free (data); else g_free (data); } }
static int insert_rr(zone_contents_t *z, const knot_rrset_t *rr, zone_node_t **n, bool nsec3) { if (z == NULL || knot_rrset_empty(rr) || n == NULL) { return KNOT_EINVAL; } // check if the RRSet belongs to the zone if (!knot_dname_is_sub(rr->owner, z->apex->owner) && !knot_dname_is_equal(rr->owner, z->apex->owner)) { return KNOT_EOUTOFZONE; } int ret = KNOT_EOK; if (*n == NULL) { *n = nsec3 ? zone_contents_get_nsec3_node(z, rr->owner) : zone_contents_get_node(z, rr->owner); if (*n == NULL) { // Create new, insert *n = node_new(rr->owner, NULL); if (*n == NULL) { return KNOT_ENOMEM; } ret = nsec3 ? zone_contents_add_nsec3_node(z, *n) : zone_contents_add_node(z, *n, true); if (ret != KNOT_EOK) { node_free(n, NULL); } } } return node_add_rrset(*n, rr, NULL); }
/* Remove a child entry (no lock) */ static int NamespaceRemove_nl(ino_t parent_ino, dev_t parent_dev, unsigned int parent_gen, char *name) { fsnode_t *p_parent = NULL; fsnode_t *p_node = NULL; int rc; LogFullDebug(COMPONENT_FSAL, "namespace: removing %lX.%ld/%s", parent_dev, parent_ino, name); /* get parent node */ p_parent = h_get_node(parent_ino, parent_dev, &rc); if(rc == HASHTABLE_ERROR_NO_SUCH_KEY) return ENOENT; else if(!p_parent) return EFAULT; else if(p_parent->inode.generation != parent_gen) return ESTALE; /* remove the lookup entry in the hash and get pointed node (if exists) */ p_node = h_del_lookup(parent_ino, parent_dev, parent_gen, name, &rc); if(rc == HASHTABLE_ERROR_NO_SUCH_KEY) { /* consider its OK */ return 0; } else if(!p_node) { return EFAULT; } assert(p_parent->n_children > 0); /* decrement parents' lookup count */ p_parent->n_children--; LogFullDebug(COMPONENT_FSAL, "namespace: Entry %lX.%ld has now link count = %u", p_node->inode.dev, p_node->inode.inum, p_node->n_lookup); /* node not in namespace tree anymore */ if(p_node->n_lookup == 0) { assert(p_node->n_children == 0); /* remove from hash table */ rc = h_del_node(p_node->inode.inum, p_node->inode.dev); if(rc != HASHTABLE_SUCCESS) { return EFAULT; } /* free the node */ node_free(p_node); } /* remove succeeded ! */ return 0; } /* NamespaceRemove_nl */
END_TEST START_TEST (parse_graph_string_test_2) { char str[] = "1 | 2 3 | 5\n" "2 | 1 3 | 4 6"; node_t *nodes; int n; int rc = parse_graph_string(str, &nodes, &n); ck_assert_int_eq(n, 2); ck_assert_int_eq(rc, 2); ck_assert_int_eq(nodes[0].id, 1); ck_assert_int_eq(nodes[0].num_out, 2); ck_assert_int_eq(nodes[0].num_in, 1); ck_assert_int_eq(nodes[0].out[0], 2); ck_assert_int_eq(nodes[0].out[1], 3); ck_assert_int_eq(nodes[0].in[0], 5); ck_assert_int_eq(nodes[1].id, 2); ck_assert_int_eq(nodes[1].num_out, 2); ck_assert_int_eq(nodes[1].num_in, 2); ck_assert_int_eq(nodes[1].out[0], 1); ck_assert_int_eq(nodes[1].out[1], 3); ck_assert_int_eq(nodes[1].in[0], 4); ck_assert_int_eq(nodes[1].in[1], 6); for (int i=0; i<n; ++i) { node_free(&nodes[i]); } free(nodes); }
void treap_delete(struct treap *t,char key) { struct node *n,*p; n = t->root; while(n && n->key!=key) { if(key > n->key) n = n->right; else n = n->left; } if(n == NULL) return; while(n->left && n->right) { if(n->left->priority < n->right->priority) right_rotate(n,&t->root); else left_rotate(n,&t->root); } p = n->left? n->left:n->right; if(p) p->parent = n->parent; if(n->parent->left == n) n->parent->left = p; else n->parent->right = p; n->left = n->right = NULL; //ATTENTION! node_free(n); return; }
void test_llist_shorten(void) { Node node; Llist list = NULL; node_alloc(&node); node.score = 0; for (int i = 0; i < 50; ++i) { llist_add(node, &list); node.score++; } node_free(&node); /* int i = 1; */ /* Element *tmp = list; */ /* while (tmp != NULL) { */ /* printf("#n = %d\n", i++); */ /* node_print(tmp->value); */ /* tmp = tmp->next; */ /* } */ /* printf("%d", llist_shorten(&list, 60)); */ /* printf("%d", llist_shorten(&list, 30)); */ /* i = 1; */ /* tmp = list; */ /* while (tmp != NULL) { */ /* printf("#n = %d\n", i++); */ /* node_print(tmp->value); */ /* tmp = tmp->next; */ /* } */ llist_free(&list); }
ret_t chula_avl_mrproper (chula_avl_generic_t *avl, chula_func_free_t free_func) { chula_avl_generic_node_t *node; chula_avl_generic_node_t *next; if (unlikely (avl == NULL)) return ret_ok; node = node_first (avl); while (node) { next = node_next (node); /* Node content */ if (free_func) { free_func (node->value); } /* Node itself */ node_free (node, avl); node = next; } return ret_ok; }
END_TEST START_TEST(test_node_delete) { node *root = node_new("d", "definition"); node *l = node_new("b", "b"); node *ll = node_new("a", "a"); node *lr = node_new("c", "c"); node_insert(root, l); node_insert(root, ll); node_insert(root, lr); // ensure correct insertions ck_assert_ptr_eq(l, root->left); ck_assert_ptr_eq(ll, root->left->left); ck_assert_ptr_eq(lr, root->left->right); ck_assert_int_eq(4, node_size(root)); ck_assert_ptr_eq(l, node_delete(root, "b")); // ensure correct reinsertion ck_assert_ptr_eq(ll, root->left); ck_assert_ptr_eq(NULL, root->right); ck_assert_ptr_eq(NULL, root->left->left); ck_assert_ptr_eq(lr, root->left->right); // node is not found in the tree anymore ck_assert_ptr_eq(NULL, node_search(root, "b")); ck_assert_int_eq(3, node_size(root)); node_free(root); }
void dict_free(Dict *d){ Node *aux, *nd; int i; for(i=0;i<HASHSIZE;i++) for(nd=d->table[i];nd!=NULL;aux=nd,nd=nd->next,node_free(aux)); free(d); }
END_TEST START_TEST (parse_graph_string_test_4) { char str[] = "2 | |\n" "5 | |"; node_t *nodes; int n; int rc = parse_graph_string(str, &nodes, &n); ck_assert_int_eq(n, 2); ck_assert_int_eq(rc, 2); ck_assert_int_eq(nodes[0].id, 2); ck_assert_int_eq(nodes[0].num_out, 0); ck_assert_int_eq(nodes[0].num_in, 0); ck_assert(nodes[0].out == NULL); ck_assert(nodes[0].in == NULL); ck_assert_int_eq(nodes[1].id, 5); ck_assert_int_eq(nodes[1].num_out, 0); ck_assert_int_eq(nodes[1].num_in, 0); ck_assert(nodes[1].out == NULL); ck_assert(nodes[1].in == NULL); for (int i=0; i<n; ++i) { node_free(&nodes[i]); } free(nodes); }
/*ARGSUSED*/ int menu_commit(WINDOW *win, node_t *current, node_t *list) { node_t *n; node_t *next; data_t *d; n = list; while(n != NULL && n->data != NULL) { d = n->data; if(d->ops != NULL && d->ops->op_commit != NULL && d->commited == BOOL_FALSE) { d->ops->op_commit(win, n, list); d->commited = BOOL_TRUE; } n = n->next; } n = list; while(n != NULL) { next = n->next; node_free(list_del(n)); n = next; } return BOOL_TRUE; }
int zone_tree_delete_empty_node(zone_tree_t *tree, zone_node_t *node) { if (!tree || !node) { return KNOT_EINVAL; } if (node->rrset_count == 0 && node->children == 0) { zone_node_t *parent_node = node->parent; if (parent_node) { parent_node->children--; fix_wildcard_child(parent_node, node->owner); if (parent_node->parent != NULL) { /* Is not apex */ // Recurse using the parent node, do not delete possibly empty parent. int ret = zone_tree_delete_empty_node(tree, parent_node); if (ret != KNOT_EOK) { return ret; } } } // Delete node zone_node_t *removed_node = NULL; zone_tree_remove(tree, node->owner, &removed_node); UNUSED(removed_node); node_free(&node, NULL); } return KNOT_EOK; }
static int zone_tree_free_node(zone_node_t **node, void *data) { UNUSED(data); if (node) { node_free(node, NULL); } return KNOT_EOK; }
void node_free(list_node_t *n) { if(n == NULL) { return; } else { node_free(n->next); free(n); } }