void insert_float_point(struct Tree *tree, struct Node *node, void *point) { int dimension = node->dimension; float *node_point = (float *) node->point; float *new_point = (float *) point; if (node_point[dimension] > new_point[dimension]) { if (node->left == NULL) { struct Node *new_node = init_node(point); node->left = new_node; new_node->parent = node; new_node->dimension = dimension ^ DIMENSION; tree->set_dimension(node, new_node); } else insert_float_point(tree, node->left, point); } else { if (node->right == NULL) { struct Node *new_node = init_node(point); node->right = new_node; new_node->parent = node; new_node->dimension = dimension ^ DIMENSION; tree->set_dimension(node, new_node); } else insert_float_point(tree, node->right, point); } }
int main() { int i, digit; pnode phead = NULL; init_node(&phead, sizeof(snode)); create_chain(phead); pnode arr[N]; for (i = 0; i < N; i++) { init_node(&arr[i], sizeof(snode)); } digit = max_digit(phead); for (i = 0; i < digit; i++) { phead_to_arr(phead, arr); arr_to_phead(phead, arr); } show_chain(phead); for (i = 0; i < N; i++) { destroy_chain(&arr[i]); } destroy_chain(&phead); return 0; }
//! Construct from ib_list_node_t. explicit pointer_list_const_iterator(ib_list_node_t* n) : m_node(n) { init_node(m_past_the_end); init_node(m_before_the_beginning); }
int main(int argc, char* argv[]) { s_node *list, *dup; s_node linkedlist, one, two, three, four; // Creating a test LinkedList init_node(&linkedlist, 0); init_node(&one, 1); init_node(&two, 2); init_node(&three, 3); init_node(&four, 4); linkedlist.next = &one; one.next = &two; two.next = &three; three.next = &four; list = &linkedlist; dup = duplicate_list(list); printf("%s\n", "Original linkedlist and Address."); print_list(list); printf("%s\n", "Duplicate linkedlist and Address."); print_list(dup); return 0; }
void init_send_sock(SEND_SOCK* p_send, int sock) { init_node(&p_send-> node); init_node(&p_send-> head); p_send-> sock = sock; }
void init_node(int left, int right, node* n = d){ n -> left = left; n -> right = right; n -> hash = 0; if(left < right){ int mid = (left + right) >> 1; init_node(left, mid, LEFT(n)); init_node(mid+1, right, RIGHT(n)); }
Node* list_from_num(int num) { Node *head = init_node(num%10); Node *curr = head; while(num/10>0) { num = num/10; curr->next = init_node(num%10); curr = curr->next; } return head; }
/*---------------------------------------------------------------------------*/ extern Boolean lac_create_port(Lac_system *system, Port_no port_no, Lac_port **port) { Lac_port *p; *port = NULL; p = &system->ports; while ((p = p->next) != &system->ports) if (p->port_no == port_no) return(False); /* else */ if (!sysmalloc(sizeof(Lac_port), &p)) return(False); *port = p; p->port_no = port_no; init_node(&p->mac, (void *)p); p->mac.rx_fn = &mac_rx; p->mac.rx_status_fn = &mac_status; p->mac.tx_status_fn = &mac_status; init_node(&p->mux, (void *)p); add_port(system, p); p->actor_admin.port_priority = Default_port_priority; p->actor_admin.port_no = port_no; p->actor_admin.system_priority = Default_system_priority; p->actor_admin.system_id = p->system->id; p->actor_admin.key = Default_key; p->actor_admin.state.lacp_activity = Default_lacp_activity; p->actor_admin.state.lacp_timeout = Default_lacp_timeout; p->actor_admin.state.aggregation = Default_aggregation; p->actor_admin.state.synchronization = False; p->actor_admin.state.defaulted = True; p->actor_admin.state.expired = False; p->partner_admin.port_priority = Default_port_priority; p->partner_admin.port_no = port_no; p->partner_admin.system_priority = Default_system_priority; p->partner_admin.system_id = Null_system; p->partner_admin.key = p->port_no; p->partner_admin.state.lacp_activity = False; /* Passive */ p->partner_admin.state.lacp_timeout = False; /* Long timeout */ p->partner_admin.state.aggregation = False; /* Individual */ p->partner_admin.state.synchronization = True; p->partner_admin.state.collecting = True; p->partner_admin.state.distributing = True; p->partner_admin.state.defaulted = True; p->partner_admin.state.expired = False; lac_init_port(system, port_no, Lacp_enabled); return(True); }
void init_node(int idx,int _l,int _r) {//初始化线段树 int mid; node[idx].l=_l;//这里不管怎样都要赋值,确定边界 node[idx].r=_r; if(_l == _r) {//如果到了底层了直接返回 return ; } mid=(_l+_r)>>1; init_node(2*idx,_l,mid);//初始化左子树 init_node(2*idx+1,mid+1,_r);//初始化右子树 }
int init_tree(const int all_violation_per_path) { dummy = (operation_t*) xmalloc(sizeof(operation_t)); init_dummy_op(dummy); node_t* sentinel = (node_t*) xmalloc(sizeof(node_t)); init_node(sentinel, ULONG_MAX, ULONG_MAX, null, null, dummy); root = (node_t*) xmalloc(sizeof(node_t)); init_node(root, ULONG_MAX, ULONG_MAX, sentinel, null, dummy); d = all_violation_per_path; return SUCCESS; }
Node* reverse_list_from_num(int num) { Node *head; int i=num, j=1; if(num/10==0) { head = init_node(num); return head; } while(i/10>0) { i = i/10; j = j*10; } head = init_node(i); head->next = list_from_num(num-(i*j)); return head; }
/* splits the index node at the given level of the given path */ PRIVATE int split_index_node(struct root *r, struct path *p, int level) { int slot = p->slots[level]; struct cache *left = p->nodes[level]; int nritems = left->u.node.header.nritems; int nrstaying = nritems/2; /* smaller half stays on the left */ int nrmoving = nritems - nrstaying; /* larger half moves to the right */ struct cache *right; blocknr_t rightnr; assert(left->will_write); /* was ensured on tree descent */ rightnr = alloc_block(r->fs_info, left, left->u.node.header.type); if (!rightnr) return -ENOSPC; right = init_node(rightnr, left->u.node.header.type, level); if (!right) return -errno; if(is_root_level(level, p)) { /* no node above, so need to grow tree */ blocknr_t new_rootnr; struct cache *c; assert(level < MAX_LEVEL - 1); /* has room to add another level */ new_rootnr = alloc_block(r->fs_info, right, right->u.node.header.type); if (!new_rootnr) return -ENOSPC; c = init_node(new_rootnr, right->u.node.header.type, level + 1); if (!c) return -errno; p->nodes[level + 1] = c; p->slots[level + 1] = 0; /* path on the left node */ insert_key_ptr(r, p, level + 1, key_for(left, 0), left->write_blocknr); r->blocknr = new_rootnr; } memmove(&right->u.node.u.key_ptrs[0], /* move larger half to right node */ &left->u.node.u.key_ptrs[nrstaying], nrmoving * sizeof(struct key_ptr)); right->u.node.header.nritems = nrmoving; memset(&left->u.node.u.key_ptrs[nrstaying], 0, /* clear moved in left */ nrmoving * sizeof(struct key_ptr)); left->u.node.header.nritems = nrstaying; p->slots[level + 1]++; /* temporarily, for inserting in parent node */ insert_key_ptr(r, p, level + 1, key_for(right, 0), rightnr); if (slot >= nrstaying) { /* need to change path to the right */ p->nodes[level] = right; p->slots[level] = slot - nrstaying; put_block(left); /* free left since it's now off the path */ } else { p->slots[level + 1]--; /* path back to left node in parent node */ put_block(right); /* free right since it's not on the path */ } return SUCCESS; }
static int addr_handler(struct cmatest_node *node) { int ret; ret = verify_test_params(node); if (ret) goto err; ret = init_node(node); if (ret) goto err; if (!is_sender) { ret = post_recvs(node); if (ret) goto err; } ret = rdma_join_multicast(node->cma_id, test.dst_addr, node); if (ret) { perror("mckey: failure joining"); goto err; } return 0; err: connect_error(); return ret; }
int main(void){ int n,i; scanf("%d",&n); LL prefix=0,suffix=0,res=0; for(i=0;i<n;i++){ scanf("%lld",&A[i]); suffix^=A[i]; } /** for my test case std::string testfile; std::cin>>testfile; std::ifstream in(testfile); in>>n; for(i=0;i<n;i++){ in>>A[i]; suffix^=A[i]; } **/ init_node(0); used_node=1; insert_node(0LL);//when the prefix is empty for(i=0;i<n;i++){ prefix^=A[i]; suffix^=A[i]; insert_node(prefix); res=max(res,find_max_node(suffix)^suffix); } printf("%lld\n",res); return res; }
static pwr_tStatus init_nodes () { pwr_tStatus sts; LstLink(sNode) *nl; sNode *np; pwr_tObjid oid; nl = LstEnd(&node_l); for ( sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts); sts = gdh_GetNextObject(oid, &oid) ) { np = init_node(oid, NULL, 1); if (np != NULL) { nl = LstIns(nl, np, node_l); } } if (LstEmp(&node_l)) errh_Info("No NodeLink objects"); return(sts); }
void CHashMap::init_pool_data(int node_total, int bucket_size, int key_size) { hash_map_->node_total_ = node_total; hash_map_->bucket_size_ = bucket_size; hash_map_->key_size_ = key_size; hash_map_->used_node_num_ = 0; hash_map_->used_bucket_num_ = 0; hash_map_->add_head_ = INVALID_BC_MEM_HANDLER; hash_map_->add_tail_ = INVALID_BC_MEM_HANDLER; hash_map_->free_list_ = INVALID_BC_MEM_HANDLER; int i; for(i = 0; i < bucket_size; i++) { hash_map_->bucket[i] = INVALID_BC_MEM_HANDLER; } //将所有节点插入到空闲链表中 THashNode* hash_node; int offset; for(i = 0; i < node_total; i++) { offset = i * (sizeof(THashNode) + key_size); hash_node = (THashNode*)((char*)hash_node_ + offset); init_node(hash_node); free_list_insert(hash_node); } return; }
END_TEST START_TEST (ut_graph_load_dictionary_prefix_search) { init_node(graph); FILE *fp = fopen("/usr/share/dict/words", "r"); wchar_t word[1000]; while (fgetws(word, 80, fp)) { word[wcslen(word)-1] = L'\0'; printf("%ls\n", word); insert_word(graph, word); } fclose(fp); PrefixResult *result = search_prefix(graph, L"app"); while(result != NULL) { printf("%ls\n", result->word); result = result->next; } clear_node(graph); }
int create_network(datacenter *dc, int type, int nnodes){ int i; void **str; dc->nw=malloc(sizeof(network)); dc->nw->nnodes=nnodes; dc->nw->cores_node=nvcores; dc->nw->free_vcores=nvcores*nnodes; dc->nw->total_vcores=nvcores*nnodes; dc->nw->n_rr = 0; dc->nw->c_rr = 0; dc->nw->utilization=0.0; dc->nw->type=type; dc->nw->n=malloc(sizeof(node)*nnodes); for(i = 0;i < nnodes;i++){ init_node(&dc->nw->n[i],i); } str = &dc->nw->str; switch(type){ case FATTREE: // str_ft* str = (str_ft*)dc->nw->str; create_network_fattree((str_ft**)str); break; default: panic("Unknown network type"); } //print_network_str(dc->nw->str); return(1); }
static int route_handler(struct cmatest_node *node) { struct rdma_conn_param conn_param; int ret; ret = init_node(node); if (ret) goto err; ret = post_recvs(node); if (ret) goto err; memset(&conn_param, 0, sizeof conn_param); conn_param.responder_resources = 1; conn_param.initiator_depth = 1; conn_param.retry_count = 5; conn_param.private_data = test.rai->ai_connect; conn_param.private_data_len = test.rai->ai_connect_len; ret = rdma_connect(node->cma_id, &conn_param); if (ret) { perror("cmatose: failure connecting"); goto err; } return 0; err: connect_error(); return ret; }
int main(void) { char *line; char *value; node *db; db = (node*)malloc(sizeof(node)); db = init_node(db); while (get_next_line(0, &line) && *line != '\0') { get_next_line(0, &value); ft_putendl("--1--"); ft_putendl(line); ft_putendl("--2--"); ft_putendl(value); sort(line, value, db); free(line); free(value); } while (get_next_line(0, &line)) { ft_putstr(line); ft_putstr(": "); ft_putendl(search(line, db)); free(line); } return (0); }
/* Parameter: Pointer to a LinkedList. * Purpose: To duplicate the Singly LinkedList without referencing the original. * Time & Space Complexity: T = O(n), S = O(n) */ struct s_node *duplicate_list(struct s_node *list) { // Checking for NULL list - Base Case if(list == NULL) { return NULL; } // Creating new LinkedList. s_node *node = new s_node; // Head pointer and tail pointer for O(1) Head/Tail insertion. head = tail = node; /* Duplicating the original list, using a current pointer to next nodes. */ s_node *current = list; while(current != NULL) { node->data = current->data; // Do not need to create a new node if the next equals to NULL. if(current->next != NULL) { s_node *new_node = new s_node; // Creating a new node for the linkedlist, and initalize it to 0. init_node(new_node, 0); node->next = new_node; node = node->next; tail = node; // Point tail to the new node. } current = current->next; } return head; }
int quiescent(app_t *app, cnodeptr_t parent, int alpha, int beta) { int i, score = -MATE; node_t node; int delta = 200; init_node(&node); assert(app); app->search.nodes++; /* max depth */ if (app->game.board->ply > (SEARCH_MAXDEPTH - 1)) { return evaluate(app->game.board); } /* draws */ if (repetitions(app) || (app->game.board->half >= 100)) { return 0; } score = evaluate(app->game.board); if (score >= beta) return beta; /* delta pruning based on a material value of delta (this should be disabled in the endgame) */ /* The idea here is that, even if our score can improve alpha, it doesn't improve it by a significant amount, so don't bother searching these nodes */ if (score < (alpha - delta)) return alpha; if (score > alpha) alpha = score; /* generate moves (with separate captures) */ generate_moves(app->game.board, &node.ml, &node.cl); for (i = 0; i < node.cl.count; i++) { /* get the next move ordered */ next_move(i, &node.cl); if (!(do_move(app->game.board, &app->game.undo, node.cl.moves[i]))) continue; score = -quiescent(app, &node, -beta, -alpha); node.made++; undo_move(app->game.board, &app->game.undo); if (score > alpha) { if (score >= beta) { return beta; } /* update alpha */ alpha = score; } } return alpha; }
void init_node_head(struct tree **phead, int size) { init_node(phead, size); int data; scanf("%d", &data); (*phead)->data = data; }
void handle_new_client(Maintainer* maintainer) { int new_socket = accept(maintainer->master_socket, (struct sockaddr *)&(maintainer->address), (socklen_t*)&(maintainer->addrlen)); if (new_socket < 0) { logger("<Server><handle_new_client>failure at handle new client accept error\n"); exit(EXIT_FAILURE); } logger("<Server><handle_new_client>New connection, socket fd is %d, ip is : %s, port : %d\n", new_socket , inet_ntoa(maintainer->address.sin_addr) , ntohs(maintainer->address.sin_port)); Node* new_node = mymalloc(sizeof(Node)); init_node(new_node); new_node->ip = maintainer->address.sin_addr.s_addr; new_node->socket_fd = new_socket; new_node->read_msg.total_len = BUFFER_SIZE; new_node->write_msg.total_len = BUFFER_SIZE; int* new_ip = mymalloc(sizeof(int)); /*TODO memory leak*/ *new_ip = maintainer->address.sin_addr.s_addr; RBTreeInsert(maintainer->nodes_ip, new_ip, new_node); FD_SET(new_socket, &(maintainer->fd_read_set)); FD_SET(new_socket, &(maintainer->fd_exception_set)); maintainer->max_sd = (maintainer->max_sd > new_socket) ? maintainer->max_sd : new_socket; struct Nodes_ll* new_ll_element = mymalloc(sizeof(struct Nodes_ll)); new_ll_element->node=new_node; new_ll_element->next=maintainer->clients; maintainer->clients=new_ll_element; }
/*---------------------------------------------------------------------------*/ extern Boolean sys_create_lan(Lan **lan) { if (!sysmalloc(sizeof(Lan), lan)) return(False); init_node((*lan), (*lan)); (*lan)->provider = (*lan); }
static int alloc_nodes(void) { int ret, i; nodes = calloc(connections, sizeof *nodes); if (!nodes) { printf("cmatose: unable to allocate memory for test nodes\n"); return -ENOMEM; } for (i = 0; i < connections; i++) { nodes[i].id = i; if (opts.dst_addr) { ret = init_node(nodes + i, info); if (ret) goto err; } } return 0; err: while (--i >= 0) destroy_node(nodes + i); free(nodes); return ret; }
name_pointer #line 339 "./cwebdir/comm-w2c.ch" add_section_name P5C(name_pointer,par,int,c,char*,first,char*,last, int,ispref) #line 863 "./cwebdir/common.w" { name_pointer p= name_ptr; char*s= first_chunk(p); int name_len= last-first+ispref; if(s+name_len> byte_mem_end)overflow("byte memory"); if(name_ptr+1>=name_dir_end)overflow("name"); (++name_ptr)->byte_start= byte_ptr= s+name_len; if(ispref){ *(byte_ptr-1)= ' '; name_len--; name_ptr->link= name_dir; (++name_ptr)->byte_start= byte_ptr; } set_prefix_length(p,name_len); strncpy(s,first,name_len); p->llink= NULL; p->rlink= NULL; init_node(p); return par==NULL?(root= p):c==less?(par->llink= p):(par->rlink= p); }
static int connreq_handler(struct fi_info *info) { struct cma_node *node; int ret; if (conn_index == connections) { ret = -ENOMEM; goto err1; } node = &nodes[conn_index++]; ret = init_node(node, info); if (ret) goto err2; ret = fi_accept(node->ep, NULL, 0); if (ret) { FT_PRINTERR("fi_accept", ret); goto err2; } return 0; err2: connects_left--; err1: printf("cmatose: failing connection request\n"); fi_reject(pep, info->handle, NULL, 0); return ret; }
void *t_fun(void *arg) { struct node *tmp; struct head *h; int elems = 0; while (1) { pthread_mutex_lock(&list_lock); if (list) { h = list; pthread_mutex_unlock(&list_lock); } else { pthread_mutex_unlock(&list_lock); sleep(1); continue; } tmp = malloc(sizeof(struct node)); init_node(tmp, ++elems); pthread_mutex_lock(&h->lock); tmp->next = h->first; // RACE! h->first = tmp; // RACE! pthread_mutex_unlock(&h->lock); printf("Inserted element %d.\n", elems); sleep(1); } return NULL; }
node_t * list_insert(node_t *head, element_t val) { node_t *prev, *curr, *node; init_node(&node, val); if (NULL == head) { return node; } prev = curr = head; while (NULL != curr && curr->value <= val) { prev = curr; curr = curr->next; } if (prev == curr) { node->next = head; head = node; } else { prev->next = node; node->next = curr; } return head; }