void tree_delete(Node* &T, Node *x) { if (NIL == T || NIL == x) return; // y是要删除的节点 Node *y = NULL; if ((NIL == LEFT(x)) || (NIL == RIGHT(x))) y = x; else y = tree_successor(x); if (y != x) KEY(x) = KEY(y); // y肯定只有一个孩子 Node * z = (NIL != LEFT(y))? LEFT(y): RIGHT(y); // 即使z是NIL,也给挂上,否则会影响rb_delete_fixup PARENT(z) = PARENT(y); if (NIL == PARENT(y)) { // 根节点发生变化 T = z; } else if (IS_LEFT(y)){ LEFT(PARENT(y)) = z; } else { RIGHT(PARENT(y)) = z; } // 调整路径上节点的max值 Node *p = PARENT(z); while (NIL != p) { MAX(p) = max(MAX(LEFT(p)), MAX(RIGHT(p)), HIGH(KEY(p))); p = PARENT(p); } // 如果y是黑色,说明破坏红黑树的规则;如果y是红色,则不会破坏 if (IS_BLACK(y)) { rb_delete_fixup(T, z); } free_node(y); }
/* remove all entries of the scope from the symbol table */ static void kill_scope(ScopeType scope) { register int i; register struct symbol *p, **q, *r; for (i = 0; i < HASHSIZE; i++) { q = &htab[i]; for (p = htab[i]; p; p = r) { r = p->next; if (p->scope == scope) { *q = p->next; free_node(p); } else q = &p->next; } } }
static INLINE int remove_empty_leaf(struct node *n) { register int i; /* * Check followings * This node doens't have 'value' * This node is leaf. */ for (i = 0; i < 16; i++) if (n->n[i]) break; if (i >= 16 /* Is this leaf? */ && !n->v) { /* Doesn't this have 'value'? */ /* there is no 'value'. So, free callback is not required */ free_node(n, NULL, FALSE); return 1; /* true */ } else return 0;/* false */ }
static void node_no_right(AVLTREE *b, struct bitree_node *node) { struct bitree_node **parent = parent_link(node); if (parent == NULL) b->root = node->left; else *parent = node->left; if (node->left != NULL) { node->left->parent = node->parent; update_height_balance(b, node->left); } else { update_height_balance(b, node->parent); } free_node(b, node); }
static BOOL removeHWNDFromHistory(HWND hwnd){ node* currentNode = hwdHistory; node* previousNode = NULL; while(currentNode && currentNode->windows != hwnd){ previousNode = currentNode; currentNode = currentNode->next; } if (! currentNode) return FALSE; if (previousNode == NULL) hwdHistory = currentNode->next; else previousNode->next = currentNode->next; free_node(currentNode); return TRUE; }
/* * This is here so that we can dynamically add viodasd * devices without exposing all the above infrastructure. */ struct vio_dev *vio_create_viodasd(u32 unit) { struct device_node *vio_root; struct device_node *np; struct vio_dev *vdev = NULL; vio_root = of_find_node_by_path("/vdevice"); if (!vio_root) return NULL; np = do_device_node(vio_root, "viodasd", FIRST_VIODASD + unit, unit, "block", "IBM,iSeries-viodasd", NULL); of_node_put(vio_root); if (np) { vdev = vio_register_device_node(np); if (!vdev) free_node(np); } return vdev; }
int main(void) { link_t p = make_node(10); link_insert(p); p = make_node(5); link_insert(p); p = make_node(90); link_insert(p); p = link_search(5); link_delete(p); free_node(p); link_traverse(link_print); link_destroy(); return 0; }
extern status circ_delete_node(list *p_L , list node ) { list L ; if(empty_circ_list(*p_L) == TRUE ) return ERROR ; if(node == NEXT(node)) *p_L = NULL ; else { for(L = NEXT(*p_L) ; L != *p_L && NEXT(L) != node ; L = NEXT(L) ) ; if (NEXT(L) != node) return ERROR ; NEXT(L) = NEXT(node) ; if( node == *p_L ) *p_L = L ; } free_node(&node) ; return OK ; }
int list_popn(list *pp, int index) { if (isnull(*pp)) { fprintf(stderr, "popn: index out of range"); exit(EXIT_OUT_OF_RANGE); } node **qq = pp; for (int j = 0; j < index; j++) { qq = &(*qq)->next; if ((*qq) == NULL) { fprintf(stderr, "popn: index out of range.\n"); exit(EXIT_OUT_OF_RANGE); } } int result = (*qq)->val; node *t = *qq; free_node(t); *qq = (*qq)->next; return result; }
void *sup_node(t_node *node) { t_node *ret; if (node == NULL) return (NULL); ret = NULL; if (node->next != NULL) { ret = node->next; ret->prev = node->prev; } if (node->prev != NULL) { ret = node->prev; ret->next = node->next; } free_node(node); return (first_node(ret)); }
EC_API void ec_list_destroy( ec_list list ) { ec_list_node node, next; check_list(list); if (! list) return; node = HEAD(list); next = NULL; while (node) { check_node(node); next = NEXT(node); free_node( node ); node = next; } del_magic_list(list); ec_free( list ); }
Obj *objlist_take_first(ObjList **objlist) { ObjList *node; Obj*obj; optimise(objlist); node=*objlist; if(node==NULL) return NULL; obj=node->watch.obj; assert(obj!=NULL); free_node(objlist, node); return obj; }
void remove_from_list(List **list, int index) { int pos = 0; List *ptr = *list; List *tmp; if (index < 0) return; if (list_size_6(*list) <= index) return; if (index == 0) { *list = (*list)->next; return; } while (pos < index-2) { pos++; ptr = ptr->next; } tmp = ptr->next->next; free_node(ptr->next); ptr->next = tmp; }
int delete_node_by_value(struct node **list, int n) { struct node *tmp = NULL; if ((*list)->data == n) { return delete_head(list); } for (tmp = *list; tmp != NULL && tmp->data != n; tmp = tmp->next); if (tmp == NULL) return 0; if (tmp->prev != NULL) tmp->prev->next = tmp->next; if (tmp->next != NULL) tmp->next->prev = tmp->prev; return free_node(tmp); }
SEXP vlmc_sim(SEXP vlmc_R, SEXP nsim_) { /* Given a fitted VLMC (with |alphabet| = m), simulate a new series y[1..N], where N = data_len */ int N = asInteger(nsim_), next_ind = 0, nprot = 1; if (!isInteger(vlmc_R)) { vlmc_R = PROTECT(coerceVector(vlmc_R, INTSXP)); nprot++; } SEXP res = PROTECT(allocVector(INTSXP, N)); // the result int *y = INTEGER(res), m = INTEGER(vlmc_R)[0]; // = |alphabet| node_t *top = load_tree(INTEGER(vlmc_R), &next_ind, LENGTH(vlmc_R), /*level*/ 0, /*Debug*/ 0); GetRNGstate(); for (int i = 0; i < N; i++) { /* Find the context, descending the tree, given y[i-1], y[i-2],... : */ node_t *this, *temp; int j; for (j = 1, this = top; j <= i && (temp = this->child[y[i - j]]) != NULL; j++, this = temp) ; int count = 0; double r = (double) this->total * unif_rand(); for (j = 0; j < m; j++) { count += this->count[j]; if (r <= count) { y[i] = j; break; } } } PutRNGstate(); free_node(top);/* do not leak ! */ UNPROTECT(nprot); return res; }
int drslot_chrp_pci(struct options *opts) { int rc; struct dr_node *all_nodes; all_nodes = get_hp_nodes(); if (all_nodes == NULL) { say(ERROR, "There are no PCI hot plug slots on this system.\n"); return -1; } #ifdef DBG_HOT_PLUG print_slots_list(all_nodes); #endif if (!opts->usr_drc_name) opts->usr_drc_name = find_drc_name(opts->usr_drc_index, all_nodes); switch (opts->action) { case ADD: rc = do_add(opts, all_nodes); break; case REMOVE: rc = do_remove(opts, all_nodes); break; case REPLACE: rc = do_replace(opts, all_nodes); break; case IDENTIFY: rc = do_identify(opts, all_nodes); break; default: say(ERROR, "Invalid operation specified!\n"); rc = -1; break; } free_node(all_nodes); return rc; }
void tree_delete(Node* &T, Node *x) { if (NIL == T || NIL == x) return; // y是要删除的节点 Node *y = NULL; if ((NIL == LEFT(x)) || (NIL == RIGHT(x))) y = x; else y = tree_successor(x); if (y != x) KEY(x) = KEY(y); // y肯定只有一个孩子 Node * z = (NIL != LEFT(y))? LEFT(y): RIGHT(y); // 即使z是NIL,也给挂上,否则会影响rb_delete_fixup PARENT(z) = PARENT(y); if (NIL == PARENT(y)) { // 根节点发生变化 T = z; } else if (IS_LEFT(y)){ LEFT(PARENT(y)) = z; } else { RIGHT(PARENT(y)) = z; } // 沿着y节点向上,更新路径上每个节点的size Node *p = y; while (NIL != (p=PARENT(p))) { SIZE(p)--; } // 如果y是黑色,说明破坏红黑树的规则;如果y是红色,则不会破坏 if (IS_BLACK(y)) { rb_delete_fixup(T, z); } free_node(y); }
void remove_kbnode( KBNODE *root, KBNODE node ) { KBNODE n, nl; for( n = *root, nl=NULL; n; n = nl->next ) { if( n == node ) { if( n == *root ) *root = nl = n->next; else nl->next = n->next; if( !is_cloned_kbnode(n) ) { free_packet( n->pkt ); xfree( n->pkt ); } free_node( n ); } else nl = n; } }
int main(int argc, const char * argv[]) { for (size_t k = 0; k < 10000; k++) { node_t *s = create_stack(); if (stack_empty(s)) printf("Stack is empty.\n"); for (item_t i = 0; i < 1000; i++) push(i, s); for (item_t i = 0; i < 1000; i++) { item_t v = pop(s); printf("%d ", v); } printf("\n"); free_node(); } return 0; }
/* * repairing the damage along a freshly cut edge */ static void heal_right_edge(bt_pyobject *tree) { int i, j, original_depth = tree->depth; bt_node_t *node, *next; /* first pass, decrement the tree depth and free * the root for every consecutive empty root */ node = tree->root; for (i = 0; i < original_depth; ++i) { next = ((bt_branch_t *)node)->children[node->filled]; if (node->filled) break; else { free_node(1, node); tree->depth--; tree->root = node = next; } } original_depth = tree->depth; /* second pass, grow any nodes that are too small along the right edge */ BT_STACK_ALLOC_PATH(tree) for (i = 1; i <= tree->depth; ++i) { if (tree->depth < original_depth) { i--; original_depth = tree->depth; } node = tree->root; for (j = 0; j <= i; ++j) { path.lineage[j] = node; path.indexes[j] = node->filled; if (j < i) node = ((bt_branch_t *)node)->children[node->filled]; } path.depth = i; if (node->filled < (tree->order / 2)) grow_node(&path, (tree->order / 2) - node->filled); } }
/** * Parse an XML string into a nested list. * The second parameter indicates if body text (text within XML tags) * should show up among the children of the tag or in its own * section. * * See documentation (ext-xml.README) for examples. */ static package parse_xml(const char *data, int bool_stream) { /* * FIXME: Feed expat smaller chunks of the string and * check for task timeout between chunks * */ int decoded_length; const char *decoded; package result; XML_Parser parser = XML_ParserCreate(NULL); XMLdata *root = new_node(NULL, ""); XMLdata *child = root; decoded_length = strlen(data); decoded = data; XML_SetUserData(parser, &child); XML_SetElementHandler(parser, xml_startElement, xml_endElement); if(bool_stream) { XML_SetCharacterDataHandler(parser, xml_streamCharacterDataHandler); } else { XML_SetCharacterDataHandler(parser, xml_characterDataHandler); } if (!XML_Parse(parser, decoded, decoded_length, 1)) { Var r; r.type = TYPE_INT; r.v.num = XML_GetCurrentByteIndex(parser); flush_nodes(child); result = make_raise_pack(E_INVARG, XML_ErrorString(XML_GetErrorCode(parser)), r); } else { finish_node(root); result = make_var_pack(var_ref(root->element.v.list[4].v.list[1])); free_node(root); } XML_ParserFree(parser); return result; }
/** Insert a node into the linked list. Insert (in increasing * alphabetical order) only if abbrev is unique. * @param abbrev_short The abbreviated form. * @param abbrev_full The abbreviation written out in full. * @param key The key to use for sorting the list. * @return none */ void insert_node(char *abbrev_short, char *abbrev_full, char *key) { int cmp; node *new_node; node *current_node = list_start; node *previous_node = NULL; /* create new node */ new_node = malloc(sizeof(node)); if(new_node == NULL) errmess(ERRMESS_NO_MEM); new_node->abbrevitem = make_abbrevitem(abbrev_short, abbrev_full); new_node->key = key; new_node->abbrev_short = abbrev_short; new_node->abbrev_full = abbrev_full; /* Loop through term until insertion point found */ while(current_node != NULL && (cmp = nodecasecmp(new_node, current_node)) >= 0) { if(!cmp) { /* already exists in list */ free_node(new_node); return; } /* go to next node */ previous_node = current_node; current_node = current_node->next; } /* insert new node */ new_node->next = current_node; if(previous_node == NULL) list_start = new_node; else previous_node->next = new_node; return; }
int main(void) { int state; char c; sleep_time = 1000 * 300; //1s = 1000ms 1ms = 1000us state = 0; len = 3; score = 0; init_game(); while(0 <= state) { print_game(); usleep(sleep_time); state = move(); system("stty raw -echo"); if(kbhit()) { c = getchar(); if('a' == c && 'd' != direc) direc = 'a'; else if('s' == c && 'w' != direc) direc = 's'; else if('d' == c && 'a' != direc) direc = 'd'; else if('w' == c && 's' != direc) direc = 'w'; } system("stty cooked echo"); } free_node(); return 0; }
int set_spot(t_elem **spot, char *str, int fd) { const char *carac[4]; t_elem *tmp; carac[0] = INTENSITY; carac[1] = COLOR; carac[2] = ORIGIN; carac[3] = NULL; if (!(tmp = append_list(spot))) return (my_putstr(MALLOC_E, 2)); set_item_ID(tmp, str); if (!get_item_carac(tmp, carac, fd)) { my_putstr("\e[1;31mCaracteristic missing or invalid, ", 2); fprintf(stderr, "item [%s] is gonna be ignored.\n", str); my_putstr("-------------------------------\n\e[0;m", 2); free(str); while ((str = get_next_line(fd)) && my_strcmp(NEXT, str)) free(str); free_node(spot); }
int CHashMap::delete_node(THashNode* node, char* data, int* data_len) { //旧节点存在 if(data != NULL && data_len != NULL) { //返回旧数据 if(allocator_.merge(node->chunk_head_, node->chunk_len_, data, data_len) != 0) { return -1; } } else if(data_len != NULL) { *data_len = node->chunk_len_; } delete_from_add_list(node); free_node(node); free_list_insert(node); return 0; }
/** * Delete the edge from the given start node to the given end node (processes or resources) */ int delete_out_edge(memory_layout *mem, node *start, node *end) { node *cur = start->out_edges; node *prev = NULL; while(cur != NULL && cur->data != end) { prev = cur; cur = cur->next; } if(cur == NULL) return 1; if(prev == NULL) { start->out_edges = cur->next; } else { prev->next = cur->next; } free_node(mem, cur); return 1; }
static int free_node(DB_NODE *node) { /* if node is NULL */ if (!node) return 0; /* free children */ DB_NODE *node2 = node->c; while (node2) { DB_NODE *node2s = node2->s; free_node(node2); node2 = node2s; } /* free itself */ if (node->uri) free(node->uri); if (node) free(node); return 0; }
/* Define a function for processing a timer interrupt. * On every timer interrupt, call the NTP timer to send packets and process * the clock and then call the receive function to receive packets. */ void sim_event_timer(Event *e) { struct recvbuf *rbuf; /* Call the NTP timer. * This will be responsible for actually "sending the packets." * Since this is a simulation, the packets sent over the network * will be processed by the simulate_server routine below. */ timer(); /* Process received buffers */ while (!empty(recv_queue)) { rbuf = (struct recvbuf *)dequeue(recv_queue); (rbuf->receiver)(rbuf); free_node(rbuf); } /* Arm the next timer interrupt. */ enqueue(event_queue, event(simulation.sim_time + (1 << EVENT_TIMEOUT), TIMER)); }
/** * release_hp_children * * @param parent_drc_name * @returns 0 on success, !0 otherwise */ int release_hp_children(char *parent_drc_name) { struct dr_node *hp_list, *slot; int rc; hp_list = get_hp_nodes(); for (slot = hp_list; slot; slot = slot->next) if (!strcmp(parent_drc_name, slot->drc_name)) break; if (slot == NULL) { rc = -EINVAL; goto out; } rc = release_hp_children_from_node(slot); out: free_node(hp_list); return (rc < 0) ? rc : 0; }
int rs_truncate(const char *path, off_t length) { log_msg("OP TRUNCATE %s: %d bytes", path, length); struct rs_node *node = get_node_remote_via_parent(path, true); if(! node) { node = make_node(path); } if(node->is_dir) { return -EISDIR; } int prev = node->size; node->size = length; node->data = realloc(node->data, length); if(prev < length) { memset(node->data + prev, 0, length); } int result = put_node_remote(path, node); free_node(node); return result == 0 ? 0 : -EIO; }