END_TEST START_TEST(next_node_test) { struct pbsnode *result = NULL; struct pbsnode node; struct node_iterator it; initialize_pbsnode(&node, NULL, NULL, 0, FALSE); memset(&it, 0, sizeof(it)); it.node_index = NULL; allnodes.lock(); allnodes.clear(); allnodes.unlock(); result = next_node(NULL, &node, &it); fail_unless(result == NULL, "NULL input all_nodes fail"); /*TODO: NOTE: needs more complicated solution to get apropriate result*/ result = next_node(&allnodes, NULL, &it); fail_unless(result == NULL, "NULL input pbsnode fail"); result = next_node(&allnodes, &node, NULL); fail_unless(result == NULL, "NULL input iterator fail"); result = next_node(&allnodes, &node, &it); fail_unless(result == NULL, "next_node fail"); }
PropPtr next_node(PropPtr ptr, char *name) { PropPtr from; int cmpval; if (!ptr) return NULL; if (!name || !*name) return (PropPtr) NULL; cmpval = Comparator(name, PropName(ptr)); if (cmpval < 0) { from = next_node(AVL_LF(ptr), name); if (from) return from; return ptr; } else if (cmpval > 0) { return next_node(AVL_RT(ptr), name); } else if (AVL_RT(ptr)) { from = AVL_RT(ptr); while (AVL_LF(from)) from = AVL_LF(from); return from; } else { return NULL; } }
EXPORT void print_linked_node_list( INTERFACE *intfc) { NODE **n, *m; int i, node_count; n = intfc->nodes; if (! n) { (void) printf("NULL node list on intfc\n"); return; } (void) printf("\tnode list - intfc %llu\n",(long long unsigned int)interface_number(intfc)); for (node_count = 0; n && *n; ++n, ++node_count) ; m = first_node(intfc); for (i = 0; i <= node_count + 2; ++i) { if (m != NULL) { (void) printf("prev %llu m %llu next %llu ", (long long unsigned int)node_number(prev_node(m)), (long long unsigned int)node_number(m), (long long unsigned int)node_number(next_node(m))); print_propagation_status(m); } else break; m = next_node(m); } } /*end print_linked_node_list*/
/** * next_node locates and returns the next node in the AVL (prop directory) * or NULL if there is no more. It is used for traversing a prop directory. * * @param ptr the AVL to navigate * @param name The "previous path" ... what is returned is the next path * after this one * @return the property we found, or NULL */ PropPtr next_node(PropPtr ptr, char *name) { PropPtr from; int cmpval; if (!ptr) return NULL; if (!name || !*name) return (PropPtr) NULL; cmpval = strcasecmp(name, PropName(ptr)); if (cmpval < 0) { from = next_node(ptr->left, name); if (from) return from; return ptr; } else if (cmpval > 0) { return next_node(ptr->right, name); } else if (ptr->right) { from = ptr->right; while (from->left) from = from->left; return from; } else { return NULL; } }
static struct trie__node *next_node(struct trie__view *t) { //printf("stack index =%d \n", t->stack_index); struct trie__node *n = t->stack[t->stack_index].node; //printf("Is it here?\n"); // printf("t->stack_index %d\n", t->stack_index); //printf("t->children %p\n", n->children); if (t->stack_index < 0) { //printf("1?\n"); return NULL; } else if (n->children == NULL) { //printf("!!!\n"); return t->stack[t->stack_index--].node; //yield node then move back one } else if (t->stack[t->stack_index].stack_child_index == -1) // -1 when children not null equals unexplored set of chieldren. { //printf("coring here\n"); t->stack[t->stack_index].stack_child_index = 0; // Going into the first child t->stack_index++; t->stack[t->stack_index].stack_child_index = -1; t->stack[t->stack_index].node = t->stack[t->stack_index-1].node->children + 0; return next_node(t); } else { //printf("key = %c\n", t->stack[t->stack_index].node->children[t->stack[t->stack_index].stack_child_index].key); //printf("things %d %d\n", t->stack_index, t->stack[t->stack_index].stack_child_index); if (t->stack[t->stack_index].stack_child_index < t->stack[t->stack_index].node->last_i) { //printf("or here %d %d\n", t->stack[t->stack_index].stack_child_index, t->stack[t->stack_index].node->last_i); (t->stack[t->stack_index].stack_child_index)++; // Moving on to next child t->stack_index++; //printf("mmmkey = %c\n", t->stack[t->stack_index].node->children[t->stack[t->stack_index].stack_child_index].key); //printf("things %d %d\n", t->stack_index, t->stack[t->stack_index].stack_child_index); t->stack[t->stack_index].stack_child_index = -1; t->stack[t->stack_index].node = t->stack[t->stack_index-1].node->children + (t->stack[t->stack_index-1].stack_child_index); // This addition >0 as in this clause. //printf("moving on to next node\n"); return next_node(t); //printf("post next node\n"); } else { // Yield current and move up one //printf("???\n"); return t->stack[t->stack_index--].node; } } return NULL; }
/****************************************************************************** ** Name: bsp_clear ** Params: ** Return: ** Descriptions: ** Clear all polygon in tree *******************************************************************************/ son_bool_t bsp_clear(bsp_node *tree) { bsp_node *nxt = tree; polygon3d_node *pol_node, *tmp; unsigned short n, i; if (NULL == nxt || nxt->polygons.count == 0) return son_FALSE; bsp_clear(nxt->back); bsp_clear(nxt->front); n = nxt->polygons.count; pol_node = (polygon3d_node *)head_node(&nxt->polygons); for (i = 1; i < n; ++i) { tmp = pol_node; pol_node = \ (polygon3d_node *)next_node(&nxt->polygons, (node2 *)pol_node); polygon3d_clear(&tmp->polygon3d); free(tmp); nxt->polygons.count--; } polygon3d_clear(&pol_node->polygon3d); nxt->polygons.count--; free(pol_node); free(tree); return son_TRUE; }
EXPORT void set_node_doubly_linked_list( INTERFACE *intfc) { NODE **n; n = intfc->nodes; first_node(intfc) = *n; prev_node(*n) = NULL; for (; *(n+1); ++n) { next_node(*n) = *(n+1); prev_node(*(n+1)) = (*n); } last_node(intfc) = *n; next_node(*n) = NULL; } /*end set_node_doubly_linked_list*/
int ReadNew (int sd, c_tree * ct) { GIV new_data; int counter = 0; int total_counter = 0; Node *curNode; int MustSend; time_t new_time; curNode = first_node (ct); fprintf(stderr,"ReadNew(%d) nodes=%d\n",sd,ct->numNodes); while (curNode) { MustSend = 0; new_time = time (NULL); new_data.Ident = curNode->data.Ident; new_data.Reliability = GetItemInfo (new_data.Ident, &new_data.Value, &new_data.ELRange, &new_data.EHRange); //fprintf(stderr,"In ask new-Ident: %d Rel: %d\n", new_data.Ident, // new_data.Reliability ); if (fabsf (new_data.Value - curNode->data.Value) > curNode->si.DeadZone) { if (labs (new_time - curNode->access_time) > curNode->si.DeadTime) { MustSend = 1; } } else { if (new_data.Reliability != curNode->data.Reliability || fabsf (new_data.ELRange - curNode->data.ELRange) > PRECISION || fabsf (new_data.EHRange - curNode->data.EHRange) > PRECISION) { MustSend = 1; } } if (MustSend) { curNode->access_time = new_time; memcpy (&(curNode->data), &new_data, sizeof (GIV)); send (sd, &(curNode->data), sizeof (GIV), MSG_DONTWAIT); // fprintf(stderr,"SEND!!! Rel=%d Ident=%d\n",curNode->data.Reliability,curNode->data.Ident); counter++; } curNode = next_node (curNode); total_counter++; } if (counter == 0 || counter != total_counter) // not new data or send some of data { new_data.Ident = -1; new_data.Value = 3.1415926; send (sd, &new_data, sizeof (GIV), MSG_DONTWAIT); } return 1; }
int ReadAll (int sd, c_tree * ct) { int s,i=0; Node *curNode; curNode = first_node (ct); fprintf(stderr,"1: ReadAll(%d) nodes=%d\n",sd,ct->numNodes); while (curNode) { //fprintf(stderr, "--------------Ident: %d\n", curNode->data.Ident ); //fflush(stderr); curNode->data.Reliability = GetItemInfo (curNode->data.Ident, &curNode->data.Value, &curNode->data.ELRange, &curNode->data.EHRange); curNode->access_time = time (NULL); s = send (sd, &(curNode->data), sizeof (GIV), MSG_DONTWAIT); if(s<1) fprintf(stderr,"-----------------------------s[%d]=%d\n",i,s); //else fprintf(stderr,"ident=%d rel=%d\n",curNode->data.Ident,curNode->data.Reliability); curNode = next_node (curNode); i++; } fprintf(stderr,"2: ReadAll() send %d Items\n",i); return 1; }
/* Parse the object tag corresponding to a list item. * * At this step we look for all of the "param" child tags, using this information * to build up the information about the list item. When we reach the </object> * tag we know that we've finished parsing this list item. */ static IndexItem *parse_index_sitemap_object(HHInfo *info, stream_t *stream) { strbuf_t node, node_name; IndexItem *item; strbuf_init(&node); strbuf_init(&node_name); item = heap_alloc_zero(sizeof(IndexItem)); item->nItems = 0; item->items = heap_alloc_zero(0); item->itemFlags = 0x11; while(next_node(stream, &node)) { get_node_name(&node, &node_name); TRACE("%s\n", node.buf); if(!strcasecmp(node_name.buf, "param")) { parse_index_obj_node_param(item, node.buf, info->pCHMInfo->codePage); }else if(!strcasecmp(node_name.buf, "/object")) { break; }else { WARN("Unhandled tag! %s\n", node_name.buf); } strbuf_zero(&node); } strbuf_free(&node); strbuf_free(&node_name); return item; }
SparseNode crm114__list_search(unsigned int c, SparseNode init, SparseElementList *l) { SparseNode curr = init; if (!l) { if (CRM114__MATR_DEBUG_MODE) { fprintf(stderr, "crm114__list_search: null list.\n"); } return make_null_node(l->compact); } if (crm114__list_is_empty(l)) { return make_null_node(l->compact); } if (c <= node_col(l->head)) { return l->head; } if (c >= node_col(l->tail)) { return l->tail; } while (!null_node(curr) && node_col(curr) < c) { curr = next_node(curr); } while (!null_node(curr) && node_col(curr) > c) { curr = prev_node(curr); } return curr; }
void eval_current(void) { int tag; next_node(); tag = tag_of(input); switch(tag) { case TAG_CD: eval_cd(); break; case TAG_PRIMITIVE: ((primitive*)input)->block(); break; case TAG_SYMBOL: eval_symbol(); break; case TAG_INT: case TAG_ARRAY: case TAG_STRING: case TAG_NIL: case TAG_CONTEXT: execute_waiter(); break; case TAG_I_S: push(wait_stack,((inp_stub*)input)->func); break; default: printf("evaluated object of unknown tag:%i ",tag); break; } check_gc(0.5 KB); }
/* Note: Finds the next alphabetical property, regardless of the existence of the original property given. */ PropPtr propdir_next_elem(PropPtr root, char *path) { PropPtr p; char *n; if (!root) return (NULL); while (*path && *path == PROPDIR_DELIMITER) path++; if (!*path) return (NULL); n = index(path, PROPDIR_DELIMITER); while (n && *n == PROPDIR_DELIMITER) *(n++) = '\0'; if (n && *n) { /* just another propdir in the path */ p = locate_prop(root, path); if (p && PropDir(p)) { /* yup, found the propdir */ return (propdir_next_elem(PropDir(p), n)); } return (NULL); } else { /* aha, we are finally to the property subname itself. */ return (next_node(root, path)); } }
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); }
bool Dawg::match_words(WERD_CHOICE *word, inT32 index, NODE_REF node, UNICHAR_ID wildcard) const { EDGE_REF edge; inT32 word_end; if (wildcard != INVALID_UNICHAR_ID && word->unichar_id(index) == wildcard) { bool any_matched = false; NodeChildVector vec; this->unichar_ids_of(node, &vec); for (int i = 0; i < vec.size(); ++i) { word->set_unichar_id(vec[i].unichar_id, index); if (match_words(word, index, node, wildcard)) any_matched = true; } word->set_unichar_id(wildcard, index); return any_matched; } else { word_end = index == word->length() - 1; edge = edge_char_of(node, word->unichar_id(index), word_end); if (edge != NO_EDGE) { // normal edge in DAWG node = next_node(edge); if (word_end) { if (debug_level_ > 1) word->print("match_words() found: "); return true; } else if (node != 0) { return match_words(word, index+1, node, wildcard); } } } return false; }
//NODE END QUERY BEFORE CALLING THIS FUNCTION MUST DELETE ALL LINKEDLIST NODES BELONGING TO SUCH QUERY void TrieDelete(Trie_t* trie, char*str, int length, int type) { TrieNode_t* current = &(trie->root); #ifdef CORE_DEBUG printf("----> deleting %d characters\n", length); puts(str); #endif int i; for (i = 0; i < length; i++) { TrieNode_t *next = next_node(current, str[i]); next->count[type]--; if (next->count[0] + next->count[1] + next->count[2] == 0) { current->next[str[i] - BASE_CHAR] = 0; } // if (current->count[0] + current->count[1] + current->count[2] == 0 // && current != &(trie->root)) { // deleteTrieNode(current); // } current = next; } current->counter++; //Alternative Implementation:Delete LinkedList node here (note:full traversal is required) // if (current->count[0] + current->count[1] + current->count[2] == 0 // && current != &(trie->root)) { //Note the check if current!=&(trie.root) is not really required unless we are kidding (LOL) // deleteTrieNode(current); // } }
string push_to_goals(board in) { node_b next_node(in, ""); q.push(next_node); solution = "E"; #pragma omp parallel { #pragma omp single { while(solution.compare("E") == 0) { //If execution has lasted longer than a second, return if(time(NULL) - start_t >= 60) break;; //If no solution has been found, then spawn a new task if(!q.empty()) { #pragma omp critical { next_node = q.top(); q.pop(); } #pragma omp task firstprivate(next_node) analyze(next_node); } } } } return solution; }
static ContentItem *parse_hhc(HHInfo *info, IStream *str, ContentItem *hhc_root, insert_type_t *insert_type) { stream_t stream; strbuf_t node, node_name; ContentItem *ret = NULL, *prev = NULL; *insert_type = INSERT_NEXT; strbuf_init(&node); strbuf_init(&node_name); stream_init(&stream, str); while(next_node(&stream, &node)) { get_node_name(&node, &node_name); TRACE("%s\n", node.buf); if(!strcasecmp(node_name.buf, "ul")) { ContentItem *item = parse_ul(info, &stream, hhc_root); prev = insert_item(prev, item, INSERT_CHILD); if(!ret) ret = prev; *insert_type = INSERT_CHILD; } strbuf_zero(&node); } strbuf_free(&node); strbuf_free(&node_name); return ret; }
int main(void){ int count, v, i, j, start; pi = atan(1)*4; count = 0; while (scanf("%d\n", &num_edges) == 1 && num_edges > 0) { if (count > 0) printf("\n"); printf("Case %d\n", ++count); clear_all(); build_graph(); while ((v = next_node(&start)) != -1) { traverse(v, 1, start, start); /* DEBUG */ printf("\nGraph:\n\n"); for (i = 0; i < num_nodes; i++) { for (j = 0; j < num_nodes; j++) { printf("%3d", graph[i][j]); } printf("\n"); } printf("\n"); /* End of DEBUG */ } print_freq(); } return 0; }
int main() { struct Node* head; struct Node* ptr; head = malloc(sizeof(struct Node)); assert(head != NULL); head->data = 0; head->next = 0; ptr = head; ptr->next = malloc(sizeof(struct Node)); ptr = ptr->next; ptr->data = 0; ptr->next = 0; ptr = head; next_node(&ptr); free(ptr); free(head); return EXIT_SUCCESS; }
/* removes property list --- if it's not there then ignore */ void remove_property_list(dbref player, int all) { PropPtr l; PropPtr p; PropPtr n; /* if( tp_db_readonly ) return; *//* Why did we remove this? */ #ifdef DISKBASE fetchprops(player); #endif if ((l = DBFETCH(player)->properties)) { p = first_node(l); while (p) { n = next_node(l, PropName(p)); remove_proplist_item(player, p, all); l = DBFETCH(player)->properties; p = n; } } #ifdef DISKBASE dirtyprops(player); #endif DBDIRTY(player); }
xmlNode *nth_node(xmlNode *cur, int n) { while(n > 0) { cur = next_node(cur); --n; } return cur; }
/* * count number of nodes in common betwee @to and @from * returns number of common nodes, or -errno on failure */ static int count_common_nodes(char *to, char *from) { int err, common; char *to_node, *from_node; if (!to || !from) return -EINVAL; err = 0; common = 0; to_node = NULL; from_node = NULL; do { to_node = next_node(&to, &err); if (err || !to_node) break; from_node = next_node(&from, &err); if (err || !from_node) break; if (strncmp(to_node, from_node, MAX_NAME_LEN)) break; ++to; ++from; ++common; sfree(to_node); sfree(from_node); } while (1); sfree(to_node); sfree(from_node); if (err) return err; return common; }
PropPtr next_prop(PropPtr list, PropPtr prop, char *name) { PropPtr p = prop; if (!p || !(p = next_node(list, PropName(p)))) return ((PropPtr) 0); strcpy(name, PropName(p)); return (p); }
int count_nodes(xmlNode *cur) { int c = 1; if (!cur) return 0; while ((cur = next_node(cur))) ++c; return c; }
ScmDictEntry *Scm_TreeIterNext(ScmTreeIter *iter) { if (iter->at_end) return NULL; if (iter->e) { iter->e = (ScmDictEntry*)next_node((Node*)iter->e); } else { iter->e = Scm_TreeCoreGetBound(iter->t, SCM_TREE_CORE_MIN); } if (iter->e == NULL) iter->at_end = TRUE; return iter->e; }
// method finds maximum-weight path in graph void Graph::generate_consensus(string *pconsensus) { auto& consensus = *pconsensus; vector<int> next_node(nodes_.size(), -1); vector<int> dp(nodes_.size(), -1); int max_weight = numeric_limits<int>::min(); int start_node_id = -1; // topological sort on reverse graph if (!is_sorted) { topological_sort(); } reverse(nodes_order_.begin(), nodes_order_.end()); // now no node is visited before all its children are visited // when iterating over nodes for (auto id : nodes_order_) { auto& node = nodes_[id]; const Edges& out_edges = node->getOutEdges(); if (out_edges.empty()) { // if the node has no outgoing edges, weight of heaviest // path starting at that node is zero: d(u) = 0 dp[id] = 0; next_node[id] = id; } else { // otherwise, for each outgoing edge(u, v) compute w(e) + d(v) // and set d(u) to be the largest value attained this way for (auto& e : out_edges) { int weight = e.second->getLabels().size(); if (weight + dp[e.first] > dp[id]) { dp[id] = weight + dp[e.first]; next_node[id] = e.first; } } // update max if (dp[id] > max_weight) { max_weight = dp[id]; start_node_id = id; } } } // generate consensus sequence int curr_id = start_node_id; while (curr_id != next_node[curr_id]) { consensus += nodes_[curr_id]->base(); curr_id = next_node[curr_id]; } consensus += nodes_[curr_id]->base(); }
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); } } }
/* * There are unfortunately some poorly designed mainboards around that * only connect memory to a single CPU. This breaks the 1:1 cpu->node * mapping. To avoid this fill in the mapping for all possible CPUs, * as the number of CPUs is not known yet. We round robin the existing * nodes. */ void __init numa_init_array(void) { int rr, i; rr = first_node(node_online_map); for (i = 0; i < nr_cpu_ids; i++) { if (early_cpu_to_node(i) != NUMA_NO_NODE) continue; numa_set_node(i, rr); rr = next_node(rr, node_online_map); if (rr == MAX_NUMNODES) rr = first_node(node_online_map); } }
static ContentItem *parse_sitemap_object(HHInfo *info, stream_t *stream, ContentItem *hhc_root, insert_type_t *insert_type) { strbuf_t node, node_name; ContentItem *item; *insert_type = INSERT_NEXT; strbuf_init(&node); strbuf_init(&node_name); item = heap_alloc_zero(sizeof(ContentItem)); while(next_node(stream, &node)) { get_node_name(&node, &node_name); TRACE("%s\n", node.buf); if(!strcasecmp(node_name.buf, "/object")) break; if(!strcasecmp(node_name.buf, "param")) parse_obj_node_param(item, hhc_root, node.buf, info->pCHMInfo->codePage); strbuf_zero(&node); } strbuf_free(&node); strbuf_free(&node_name); if(item->merge.chm_index) { IStream *merge_stream; merge_stream = GetChmStream(info->pCHMInfo, item->merge.chm_file, &item->merge); if(merge_stream) { item->child = parse_hhc(info, merge_stream, hhc_root, insert_type); IStream_Release(merge_stream); }else { WARN("Could not get %s::%s stream\n", debugstr_w(item->merge.chm_file), debugstr_w(item->merge.chm_file)); if(!item->name) { free_content_item(item); item = NULL; } } } return item; }