int shardcache_client_get_async(shardcache_client_t *c, void *key, size_t klen, shardcache_client_get_aync_data_cb data_cb, void *priv) { int fd = -1; char *addr = select_node(c, key, klen, &fd); if (fd < 0) { c->errno = SHARDCACHE_CLIENT_ERROR_NETWORK; snprintf(c->errstr, sizeof(c->errstr), "Can't connect to '%s'", addr); return -1; } shardcache_client_get_async_data_arg_t *arg = malloc(sizeof(shardcache_client_get_async_data_arg_t)); arg->connections = c->connections; arg->fd = fd; arg->cb = data_cb; arg->priv = priv; return fetch_from_peer_async(addr, (char *)c->auth, SHC_HDR_CSIGNATURE_SIP, key, klen, 0, 0, shardcache_client_get_async_data_helper, arg, fd, NULL); }
static linked_list_t * shc_split_buckets(shardcache_client_t *c, shc_multi_item_t **items, int *num_items) { linked_list_t *pools = list_create(); int i; for(i = 0; items[i]; i++) { shc_multi_item_t *item = items[i]; item->idx = i; char *addr = select_node(c, item->key, item->klen, NULL); tagged_value_t *tval = list_get_tagged_value(pools, addr); if (!tval || list_count((linked_list_t *)tval->value) > c->pipeline_max) { linked_list_t *sublist = list_create(); tval = list_create_tagged_sublist(addr, sublist); // put the new sublist at the beggining of the main tagged list // so that in case of multiple lists for the same node this will // be the one returned by list_get_tagged_value() list_unshift_tagged_value(pools, tval); } list_push_value((linked_list_t *)tval->value, item); } if (num_items) *num_items = i; return pools; }
static inline int shardcache_client_set_internal(shardcache_client_t *c, void *key, size_t klen, void *data, size_t dlen, uint32_t expire, int inx) { int fd = -1; char *addr = select_node(c, key, klen, &fd); if (fd < 0) { c->errno = SHARDCACHE_CLIENT_ERROR_NETWORK; snprintf(c->errstr, sizeof(c->errstr), "Can't connect to '%s'", addr); return -1; } int rc = -1; if (inx) rc = add_to_peer(addr, (char *)c->auth, SHC_HDR_SIGNATURE_SIP, key, klen, data, dlen, expire, fd, 1); else rc = send_to_peer(addr, (char *)c->auth, SHC_HDR_SIGNATURE_SIP, key, klen, data, dlen, expire, fd, 1); if (rc == -1) { close(fd); c->errno = SHARDCACHE_CLIENT_ERROR_NODE; snprintf(c->errstr, sizeof(c->errstr), "Can't set new data on node '%s'", addr); } else { connections_pool_add(c->connections, addr, fd); c->errno = SHARDCACHE_CLIENT_OK; c->errstr[0] = 0; } return rc; }
size_t shardcache_client_get(shardcache_client_t *c, void *key, size_t klen, void **data) { int fd = -1; char *addr = select_node(c, key, klen, &fd); if (fd < 0) { c->errno = SHARDCACHE_CLIENT_ERROR_NETWORK; snprintf(c->errstr, sizeof(c->errstr), "Can't connect to '%s'", addr); return 0; } fbuf_t value = FBUF_STATIC_INITIALIZER; int rc = fetch_from_peer(addr, (char *)c->auth, SHC_HDR_SIGNATURE_SIP, key, klen, &value, fd); if (rc == 0) { size_t size = fbuf_used(&value); if (data) *data = fbuf_data(&value); else fbuf_destroy(&value); c->errno = SHARDCACHE_CLIENT_OK; c->errstr[0] = 0; connections_pool_add(c->connections, addr, fd); return size; } else { close(fd); c->errno = SHARDCACHE_CLIENT_ERROR_NODE; snprintf(c->errstr, sizeof(c->errstr), "Can't fetch data from node '%s'", addr); return 0; } return 0; }
size_t shardcache_client_offset(shardcache_client_t *c, void *key, size_t klen, uint32_t offset, void *data, uint32_t dlen) { int fd = -1; char *addr = select_node(c, key, klen, &fd); if (fd < 0) { c->errno = SHARDCACHE_CLIENT_ERROR_NETWORK; snprintf(c->errstr, sizeof(c->errstr), "Can't connect to '%s'", addr); return 0; } fbuf_t value = FBUF_STATIC_INITIALIZER; int rc = offset_from_peer(addr, (char *)c->auth, SHC_HDR_SIGNATURE_SIP, key, klen, offset, dlen, &value, fd); if (rc == 0) { uint32_t to_copy = dlen > fbuf_used(&value) ? fbuf_used(&value) : dlen; if (data) memcpy(data, fbuf_data(&value), to_copy); c->errno = SHARDCACHE_CLIENT_OK; c->errstr[0] = 0; connections_pool_add(c->connections, addr, fd); fbuf_destroy(&value); return to_copy; } else { close(fd); c->errno = SHARDCACHE_CLIENT_ERROR_NODE; snprintf(c->errstr, sizeof(c->errstr), "Can't fetch data from node '%s'", addr); } fbuf_destroy(&value); return 0; }
void SJView::select_single_node(CPoint point) { SJPoint* p_point = select_node(point); if(p_point) mp_sg->mp_mesh->select_point(p_point); }
std::string DomNode::select_string(const DomString &xpath_expression) const { DomNode node = select_node(xpath_expression); if (node.is_element()) return node.to_element().get_text(); else return node.get_node_value(); }
void unselect_node(){ if(seek_port.port_type == NO_PORT && seek_port.node_viewer != NULL){ Node * nd = find_node_from_nodeview(seek_port.node_viewer); saved_text.erase(curser_pos,1); if(text_changed == true){ replace_node_with_line(saved_text,nd); } } select_node({NULL,NO_PORT,0}); }
void test() { char* ss[] = {"abc", "dfg", "hjk"}; char* s = select(ss, "abc"); printf("%s",s); node node1; node1.name="abc"; node1.age=1; node* nodes[] = {&node1}; node* selected_node = select_node(nodes, "abc"); printf("node:{name:%s,age:%d}",selected_node->name, selected_node->age); }
void SJView::select_element_node(CPoint point) { SJPoint* p_point = select_node(point); // TRACE("SJView::select_element_node %i\n", p_point); if(p_point == NULL) return; ml_elgens.add_tail(p_point); if(ml_elgens.get_count() == 4) { mp_sg->mp_mesh->add_block(ml_elgens); ml_elgens.delete_list_nodes(); mp_sg->mp_mesh->unselect_nodes(); } else p_point->m_selection = 1; }
int shardcache_client_del(shardcache_client_t *c, void *key, size_t klen) { int fd = -1; char *addr = select_node(c, key, klen, &fd); if (fd < 0) { c->errno = SHARDCACHE_CLIENT_ERROR_NETWORK; snprintf(c->errstr, sizeof(c->errstr), "Can't connect to '%s'", addr); return -1; } int rc = delete_from_peer(addr, (char *)c->auth, SHC_HDR_SIGNATURE_SIP, key, klen, fd, 1); if (rc != 0) { close(fd); c->errno = SHARDCACHE_CLIENT_ERROR_NODE; snprintf(c->errstr, sizeof(c->errstr), "Can't delete data from node '%s'", addr); } else { connections_pool_add(c->connections, addr, fd); c->errno = SHARDCACHE_CLIENT_OK; c->errstr[0] = 0; } return rc; }
/* 候補手の評価値を算出 */ int book_alphabeta(BooksNode *book_header, int depth, int alpha, int beta, int color) { if(book_header->child == NULL) { if(color == WHITE) { return -book_header->eval; } return book_header->eval; } if(depth == 0) { int i = 0, e_list[24] = { NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN, NEGAMIN }; int eval, max = NEGAMIN - 1; BooksNode *best_node[24] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; do{ if(i == 0) { book_header = book_header->child; } else { book_header = book_header->next; } eval = -book_alphabeta(book_header, depth + 1, -beta, -alpha, color ^ 1); e_list[i] = eval; best_node[i] = book_header; if(eval > max) { max = eval; } i++; }while(book_header->next != NULL); sort_book_node(best_node, e_list, i); /* ノード番号を算出 */ int node_num = select_node(e_list, i); BestNode = best_node[node_num]; return e_list[node_num]; } else { int i = 0; int eval, max = NEGAMIN - 1; do{ if(i == 0) { book_header = book_header->child; } else { book_header = book_header->next; } eval = -book_alphabeta(book_header, depth + 1, -beta, -alpha, color ^ 1); if(eval > max) { max = eval; if(max > alpha) { alpha = max; //下限値も更新 /* アルファカット */ if(beta <= alpha) { break; } } } i++; }while(book_header->next != NULL); return max; } }
CSSSelectResult CSSDocument::select(const DomElement &node, const std::string &pseudo_element) { DomSelectNode select_node(node); return select(&select_node, pseudo_element); }
int main(){ /* // Linked list de un arreglo de 10 elementos struct node_t arr[10]; printf("PREV: %x %x %x \n", &arr[0], &arr[1], &arr[2]); int i; for(i=0; i<10; i++){ arr[i].next = &arr[i+1]; printf("addr %d : 0x%p == 0x%p \n", i, &arr[i], arr[i].next); } // Hasta ahora el arr[9].next tiene basura */ int menu; do{ printf("Menu:\n"); printf("1) Create Linked List\n"); printf("2) Display\n"); printf("3) Select Node\n"); printf("4) Insert Node\n"); printf("5) Remove Node\n"); printf("6) Delete All Nodes\n"); printf("0) Exit\n"); printf("> "); scanf("%d", &menu); // 1) Create Linked List if(menu == 1){ printf(" create \n"); create_list(); } // 2) Display else if(menu == 2){ printf(" display \n"); if(display_list()){ // if it returns a 1, it failed. printf("Error: List is empty \n"); } } // 3) Select Node else if(menu == 3){ printf(" sel \n"); int selection; printf("Select Node [0:N-1]: "); scanf("%d", &selection); select_node(selection); } // 4) Insert Node else if(menu == 4){ printf(" insert \n"); int selection; printf("Insert Node [0:N-1]: "); scanf("%d", &selection); struct node_t *insert = (struct node_t*)malloc( sizeof(struct node_t) ); printf("Dato a insertar: "); scanf("%d", &(*insert).data ); insert_node(selection, insert); } // 5) Remove Node else if(menu == 5){ printf(" remove \n"); int selection; printf("Remove Node [0:N-1]: "); scanf("%d", &selection); remove_node(selection); } // 6) Delete All Nodes else if(menu == 6){ printf(" del all \n"); delete_all(); } } while(menu != 0); /* (*ptr_aux).data = (int)N; printf("%d", (*ptr_aux).data); */ /* // Linked list con selector int N; struct node_t *head = (struct node_t*)malloc( sizeof(struct node_t) ); printf("Dame N: "); scanf("%d", &N); struct node_t *ptr_aux = head; printf("size of struct %d \n", sizeof(struct node_t) ); printf("head: %p aux: %p \n", head, ptr_aux); int i; for(i=0; i<N; i++){ printf("Dato: "); scanf("%d", &(*ptr_aux).data ); printf("Addr: %p , Data: %d , ", ptr_aux, (int)(*ptr_aux).data); (*ptr_aux).next = (struct node_t*)malloc(sizeof(struct node_t)); printf("Next: %x\n", (*ptr_aux).next ); ptr_aux = (*ptr_aux).next; } int sel=0; do{ ptr_aux = head; printf("Selecciona un dato por posicion [0:N-1]: "); scanf("%d", &sel); int j; for(j=0; j<N; j++){ if(j == sel){ printf("Dato que buscas: %d, addr %p \n ", (int)(*ptr_aux).data, ptr_aux); j=N; } ptr_aux = (*ptr_aux).next; } }while(sel < N && sel >= 0); */ printf("head: %p \n", head); return 0; }
bool handle_event(MouseClick mclick){ change = true; if(mclick.button == 2){ middle_down = mclick.pressed; } if(mode == INTERACT_MODE){ NodeViewer * nv = nvp.node_viewer; if(nv == NULL){ return false; } if(mclick.button == 0 && mclick.pressed){ Node * nd = find_node_from_nodeview(nv); if(nd != NULL){ nd->handle_click(0,0,0); }else{ std::cout << "Warning. Clicking NULL node\n"; } } } if(mode == EDIT_MODE){ if(shift_down){ remove_connection_at(last_world); return false; } if(ctrl_down && mclick.button == 0 && mclick.pressed){ Node * nd = create_and_insert_node("",last_world); held_node = {node_view[nd],NO_PORT,0}; return false; } if(mclick.button == 0 && mclick.pressed){ held_node = nvp; return false; } if(mclick.button == 0 && mclick.released){ if(held_node.node_viewer != NULL){ if( seek_port.node_viewer != NULL && seek_port.port_type != NO_PORT){ Node * nd1 = find_node_from_nodeview(nvp.node_viewer); int p1 = nvp.port_nr; Node * nd2 = find_node_from_nodeview(seek_port.node_viewer); int p2 = seek_port.port_nr; if(nvp.port_type == IN_PORT && seek_port.port_type == OUT_PORT){ backend.connect_nodes(nd2,nd1,p2,p1); }else if(nvp.port_type == OUT_PORT && seek_port.port_type == IN_PORT){ backend.connect_nodes(nd1,nd2,p1,p2); } seek_port = {NULL,NO_PORT,0}; }else{ unselect_node(); select_node(held_node); held_node = {NULL,NO_PORT,0}; return false; } }else{ unselect_node(); seek_port = {NULL,NO_PORT,0}; } } } unselect_node(); }
void CL_GUIComponent::load_css_layout(const CL_String &xml_filename, const CL_String &css_filename) { CL_CSSDocument2 css_document; css_document.add_sheet(css_filename); CL_File file(xml_filename); CL_DomDocument dom(file, false); CL_DomNode cur = dom.get_document_element().get_first_child(); std::vector<CL_CSSLayoutElement> element_stack; { CL_DomSelectNode select_node(dom.get_document_element()); impl->css_element.apply_properties(css_document.select(&select_node)); impl->css_element.apply_properties(dom.get_document_element().get_attribute("style")); impl->css_element.set_col_span(dom.get_document_element().get_attribute_int("colspan", 1)); impl->css_element.set_row_span(dom.get_document_element().get_attribute_int("rowspan", 1)); } element_stack.push_back(impl->css_element); while (!cur.is_null()) { CL_CSSLayoutElement child_css_element; if (cur.is_element()) { CL_DomElement cur_element = cur.to_element(); CL_DomSelectNode select_node(cur_element); child_css_element = element_stack.back().create_element(cur_element.get_tag_name()); child_css_element.apply_properties(css_document.select(&select_node)); child_css_element.apply_properties(cur_element.get_attribute("style")); child_css_element.set_col_span(cur_element.get_attribute_int("colspan", 1)); child_css_element.set_row_span(cur_element.get_attribute_int("rowspan", 1)); } else if (cur.is_text()) { CL_DomText cur_text = cur.to_text(); element_stack.back().create_text(cur_text.get_node_value()); } CL_DomNode next = cur.get_first_child(); if (next.is_null()) { next = cur.get_next_sibling(); if (next.is_null()) { next = cur.get_parent_node(); while (!next.is_null() && next.get_next_sibling().is_null()) next = next.get_parent_node(); if (!next.is_null()) next = next.get_next_sibling(); } } else { element_stack.push_back(child_css_element); } cur = next; } CL_GraphicContext gc = get_gc(); impl->css_layout.layout(gc, get_size()); }
/*************************************************************************** * Name : SearchBooks * Brief : 定石やからCPUの着手を決定する * Return: 着手可能位置のビット列 ****************************************************************************/ INT32 SearchBooks(BooksNode *book_root, UINT64 bk, UINT64 wh, UINT32 color, UINT32 change, INT32 turn) { INT32 move = MOVE_NONE; ULONG eval = 0; BookData *book_data; BooksNode *book_header; g_booklist_cnt = 0; // 変化度設定 set_book_error(change); /* 局面から該当の定石を探す */ book_header = SearchBookInfo(book_root, book_root, bk, wh, turn); if (book_header != NULL) { /* 評価値により次の手を定石から選ぶ */ eval = book_alphabeta(book_header, 0, NEGAMIN, NEGAMAX, color); book_data = select_node(change); g_evaluation = book_data->eval; /* 指し手の対称回転変換の場合分け */ switch (TRANCE_MOVE) { case 0: move = book_data->node->move; break; case 1: { UINT64 t_move = rotate_90(1ULL << book_data->node->move); move = CountBit((t_move & (-(INT64)t_move)) - 1); } break; case 2: { UINT64 t_move = rotate_180(1ULL << book_data->node->move); move = CountBit((t_move & (-(INT64)t_move)) - 1); } break; case 3: { UINT64 t_move = rotate_270(1ULL << book_data->node->move); move = CountBit((t_move & (-(INT64)t_move)) - 1); } break; case 4: { UINT64 t_move = symmetry_x(1ULL << book_data->node->move); move = CountBit((t_move & (-(INT64)t_move)) - 1); } break; case 5: { UINT64 t_move = symmetry_y(1ULL << book_data->node->move); move = CountBit((t_move & (-(INT64)t_move)) - 1); } break; case 6: { UINT64 t_move = symmetry_b(1ULL << book_data->node->move); move = CountBit((t_move & (-(INT64)t_move)) - 1); } break; case 7: { UINT64 t_move = symmetry_w(1ULL << book_data->node->move); move = CountBit((t_move & (-(INT64)t_move)) - 1); } break; default: move = book_data->node->move; break; } } return move; }