TSNode * ts_tree_add_node(TSTree *t, int type) { if (t->node_count >= t->node_capacity) expand_tree(t); TSNode *node = (t->nodes + t->node_count); t->node_count++; ts_node_initialize(node, type); return node; }
/*================================================================= * advanced_person_edit -- *===============================================================*/ void advanced_person_edit (NODE root0) { FILE *fp; NODE expd; #ifdef DEBUG llwprintf("advanced_person_edit: %s %s %s\n", nxref(root0), ntag(root0),nval(root0)); #endif expd = expand_tree(root0); ASSERT(fp = fopen(editfile, LLWRITETEXT)); write_nodes(0, fp, NULL, expd, TRUE, TRUE, TRUE); fclose(fp); do_edit(); }
int radix_tree_insert(struct radix_s* root, unsigned long key, void* item) { int out; int err; int current_height; int next_child; struct radix_node_s* current_node; // expanding the tree until we have enough space to store the key while ((root->height == 0) || (root->max_key < key)) { if ((out = expand_tree(root))) return out; } current_height = 0; current_node = root->root_node; // finding the leaf node while (current_height+1 < root->height) { next_child = NEXT_CHILD(root, current_height, key); if (current_node->children[next_child] == NULL) // no node found, creating one { if ((err = create_node(current_node, next_child))) return err; } //next_child = NEXT_CHILD(root, current_height, key); current_node = (struct radix_node_s*) current_node->children[next_child]; current_height++; } next_child = NEXT_CHILD(root, current_height, key); // inserting the item if (current_node->children[next_child] != NULL) return -EEXIST; current_node->children[next_child] = item; current_node->count++; bitmap_set(current_node->bitmap, next_child); return 0; }
int menu_expandall(WINDOW *win, node_t *current, node_t *list) { data_t *d; if(current == NULL || current->data == NULL) { return BOOL_FALSE; } d = (data_t *)(current->data); if(d->ops != NULL && d->ops->op_expandall != NULL) { return d->ops->op_expandall(win, current, list); } expand_tree(current); redraw_screen = BOOL_TRUE; return BOOL_FALSE; }
node_t * expand_tree(node_t *node) { int i; data_t *d; if(node == NULL || node->data == NULL) { return NULL; } d = node->data; d->hidden = BOOL_FALSE; d->expanded = BOOL_TRUE; for(i = 0; i < d->nbr_children; i++) { expand_tree(d->children[i]); } return node; }
void tdu_interface_expand (int levels, int redraw) { node_s *n; long scrolllines; n = find_node_numbered(root_node, cursor_line); if (!n) return; scrolllines = expand_tree(n, levels); if (!scrolllines) return; if (!redraw && (levels > 1)) redraw = 1; if (redraw) { display_nodes(cursor_line - start_line, visible_lines - (cursor_line - start_line), root_node, cursor_line, cursor_line); tdu_interface_refresh(); } else { long maxlines = visible_lines - (cursor_line - start_line); if (scrolllines >= maxlines - 1) { display_nodes(cursor_line - start_line, visible_lines - (cursor_line - start_line), root_node, cursor_line, cursor_line); } else { tdu_interface_refresh(); winsdelln(main_window, scrolllines); display_nodes(cursor_line - start_line, scrolllines + 1, root_node, cursor_line, cursor_line); } tdu_interface_refresh(); } }
void UniformCostSearch::update_tree() { expand_tree(p_root); }
/** * Called every time there is data to read from the scanner. * Calls the scanner progress handler. * * @param cls the closure (directory scanner object) * @param client always NULL * @param msg message from the helper process */ static int process_helper_msgs (void *cls, void *client, const struct GNUNET_MessageHeader *msg) { struct GNUNET_FS_DirScanner *ds = cls; const char *filename; size_t left; #if 0 fprintf (stderr, "DMS parses %u-byte message of type %u\n", (unsigned int) ntohs (msg->size), (unsigned int) ntohs (msg->type)); #endif left = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader); filename = (const char*) &msg[1]; switch (ntohs (msg->type)) { case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: if (filename[left-1] != '\0') { GNUNET_break (0); break; } ds->progress_callback (ds->progress_callback_cls, filename, GNUNET_NO, GNUNET_FS_DIRSCANNER_FILE_START); if (NULL == ds->toplevel) ds->toplevel = expand_tree (ds->pos, filename, GNUNET_NO); else (void) expand_tree (ds->pos, filename, GNUNET_NO); return GNUNET_OK; case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: if (filename[left-1] != '\0') { GNUNET_break (0); break; } if (0 == strcmp ("..", filename)) { if (NULL == ds->pos) { GNUNET_break (0); break; } ds->pos = ds->pos->parent; return GNUNET_OK; } ds->progress_callback (ds->progress_callback_cls, filename, GNUNET_YES, GNUNET_FS_DIRSCANNER_FILE_START); ds->pos = expand_tree (ds->pos, filename, GNUNET_YES); if (NULL == ds->toplevel) ds->toplevel = ds->pos; return GNUNET_OK; case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: break; case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: if ('\0' != filename[left-1]) break; ds->progress_callback (ds->progress_callback_cls, filename, GNUNET_SYSERR, GNUNET_FS_DIRSCANNER_FILE_IGNORED); return GNUNET_OK; case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: if (0 != left) { GNUNET_break (0); break; } if (NULL == ds->toplevel) { GNUNET_break (0); break; } ds->progress_callback (ds->progress_callback_cls, NULL, GNUNET_SYSERR, GNUNET_FS_DIRSCANNER_ALL_COUNTED); ds->pos = ds->toplevel; if (GNUNET_YES == ds->pos->is_directory) ds->pos = advance (ds->pos); return GNUNET_OK; case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { size_t nlen; const char *end; if (NULL == ds->pos) { GNUNET_break (0); break; } end = memchr (filename, 0, left); if (NULL == end) { GNUNET_break (0); break; } end++; nlen = end - filename; left -= nlen; if (0 != strcmp (filename, ds->pos->filename)) { GNUNET_break (0); break; } ds->progress_callback (ds->progress_callback_cls, filename, GNUNET_YES, GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); if (0 < left) { ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left); if (NULL == ds->pos->meta) { GNUNET_break (0); break; } /* having full filenames is too dangerous; always make sure we clean them up */ GNUNET_CONTAINER_meta_data_delete (ds->pos->meta, EXTRACTOR_METATYPE_FILENAME, NULL, 0); /* instead, put in our 'safer' original filename */ GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, "<libgnunetfs>", EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, EXTRACTOR_METAFORMAT_UTF8, "text/plain", ds->pos->short_filename, strlen (ds->pos->short_filename) + 1); } ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta); ds->pos = advance (ds->pos); return GNUNET_OK; } case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: if (NULL != ds->pos) { GNUNET_break (0); break; } if (0 != left) { GNUNET_break (0); break; } if (NULL == ds->toplevel) { GNUNET_break (0); break; } ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, ds); return GNUNET_OK; default: GNUNET_break (0); break; } ds->progress_callback (ds->progress_callback_cls, NULL, GNUNET_SYSERR, GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); return GNUNET_OK; }
/*--------------------------------------------------------------- Routine : calculate_probs Purpose : Calculate the probabilities for the tree, based upon the minimal cut sets. ---------------------------------------------------------------*/ BOOL calculate_probs( char *filename, /* IN - filename to write report to */ TREE *tree, /* IN - tree */ int max_order, /* IN - max order of cut sets to use */ int prob_n_terms, /* IN - number of terms in expansion */ float unit_time ) /* IN - unit time factor to be applied */ { BitArray *stop = BitCreate(1); /* 1-bit zero */ FILE *file; Expr e; Group *g; float *probs, *cp, *imp; float p; int num_bas, num_mcs, i, j; /* char *mcs_file; */ /* int order; */ clock_t time1, time2; time_t tp; BOOL success = TRUE; float one_increment /* value for one increment of the progress bar */; /* start clock */ time1 = clock(); if ( (file = fopen(filename, "w")) == NULL) { printf("*** calculate_probs : error opening file\n"); return FALSE; } /* printf("calculate_probs()\n"); */ /* include transfered-in trees and build the primary event list * * We need to do something different to deal with Common Cause Analysis * We don't need the tree, but we do need the primary event list. * Need to add the common cause events into the primary event list. */ /* if necessary, expand tree */ expand_tree(tree); /* set probs in BASLIST from the events database */ set_bas_prob( unit_time ); /* get number of primary events */ if ((num_bas = tree->num_bas) == 0) { fclose( file ); return FALSE; } if (GenerateNumericalProbabilityCheckForInterrupt()) { success = FALSE; fclose( file ); return success; } /* create array of probabilities of primary events */ if ( !fNewMemory( (void *)&probs, ( num_bas * sizeof(float) ) ) ) { printf("\n*** calculate_probs 1 : malloc failed ***\n"); exit(1); } if ( !fNewMemory( (void *)&imp, ( num_bas * sizeof(float) ) ) ) { printf("\n*** calculate_probs : malloc failed ***\n"); exit(1); } /* fill array */ get_probs( probs ); /* get mcs list */ e = tree->mcs_expr; /* num_mcs = ExprCount(e); */ /* how many mcs are actually used? */ num_mcs = ExprCountOrder(tree->mcs_expr, max_order); /* make sure that max_term does not exceed number of mcs */ /* if number of mcs is zero then return FALSE */ if(num_mcs == 0) { return FALSE; } else if (prob_n_terms > num_mcs) { prob_n_terms = num_mcs; } /* initialise Working dialog */ /* most of the cpu time is taken up in the ExprProb() function */ /* the working dialog is incremented in the combs() function */ one_increment = 0.0; for(i = 1; i <= prob_n_terms; i++) { one_increment += nCr(num_mcs, i); } /* set up progress bar */ one_increment /= 100.0; set_one_increment(one_increment); GenerateNumericalProbabilitySetProgressBarMax(100); /* ExprPrint(e); */ /* print header */ fprintf(file, "Probabilities Analysis\n" "======================\n\n"); fprintf(file, "Tree : %s\n", tree->name); time(&tp); fprintf(file, "Time : %s\n", ctime(&tp)); fprintf(file, "Number of primary events = %d\n", num_bas); fprintf(file, "Number of minimal cut sets = %d\n", num_mcs); fprintf(file, "Order of minimal cut sets = %d\n", tree->max_order); if (max_order < tree->max_order) { fprintf(file, " (order <= %d used)\n\n", max_order); } else { fprintf(file, "\n"); } fprintf(file, "Unit time span = %f\n\n", unit_time); /* calculate cut set probabilities - use ALL the cut sets */ cp = ExprCutsetProbs(e, probs); fprintf(file, "Minimal cut set probabilities :\n\n"); i = 0; for(g=e; !BitEquals(g->b, stop); g=g->next) { char **fp = BitPara( g->b, 30 ); /* printf("(%3d) %s %-20s - %E\n", */ /* i+1, */ /* BitString(g->b), */ /* fp[0], */ /* cp[i]); */ /* */ /* for (j = 1; fp[j] != NULL; j++) { */ /* printf(" %-20s\n", fp[j]); */ /* } */ if (GenerateNumericalProbabilityCheckForInterrupt()) { success = FALSE; CleanUpOperations( file, probs, cp, imp, stop); ParaDestroy(fp); return success; } fprintf(file, "%3d %-30s %E\n", i+1, fp[0], cp[i]); for (j = 1; fp[j] != NULL; j++) { fprintf(file, " %-20s\n", fp[j]); } ParaDestroy(fp); i++; } /* calculate top level probability - use only up to max_order cut sets */ fprintf(file, "\n\n" "Probability of top level event " "(minimal cut sets up to order %d used):\n\n", max_order); p = 0; for (i = 1; i <= prob_n_terms && i <= num_mcs && !GenerateNumericalProbabilityCheckForInterrupt(); i++) { float term; char *sign, *s, *bound; p += (term = ExprProb(e, probs, max_order, i)); sign = ((i % 2) ? "+" : "-" ); s = ((i > 1) ? "s" : " " ); bound = ((i % 2) ? "upper" : "lower" ); fprintf(file, "%2d term%s %s%E = %E (%s bound)\n", i, s, sign, fabs(term), p, bound); } if (prob_n_terms >= num_mcs) { fprintf(file, "\nExact value : %E\n", p); } if (GenerateNumericalProbabilityCheckForInterrupt()) { success = FALSE; CleanUpOperations( file, probs, cp, imp, stop); return success; } /* calculate importances of individual events */ for (j = 0; j < num_bas; j++) { imp[j] = 0; } i = 0; for(g=e; !BitEquals(g->b, stop); g=g->next) { for (j = 0; j < g->b->n; j++) { if ( BitGet(g->b, (g->b->n-1) - j) ) { imp[j] += cp[i]; } } i++; } if (GenerateNumericalProbabilityCheckForInterrupt()) { success = FALSE; CleanUpOperations( file, probs, cp, imp, stop); return success; } fprintf(file, "\n\nPrimary Event Analysis:\n\n"); fprintf(file, " Event " "Failure contrib. " "Importance\n\n"); for (i = 0; i < num_bas; i++) { char *fs = BasicString(num_bas, i); fprintf(file, "%-15s %E %5.2f%%\n", fs, imp[i], 100 * imp[i] / p); strfree(fs); } time2 = clock(); /* printf("calculate_probs : num_terms = %d : time = %f\n", */ /* prob_n_terms, (time2-time1)/(float)CLOCKS_PER_SEC); */ CleanUpOperations( file, probs, cp, imp, stop); /* fclose(file); */ /* FreeMemory(probs); */ /* free(cp); */ /* FreeMemory(imp); */ return ( TRUE ); } /* calculate_probs */
void BreadthFirstSearch::update_tree() { expand_tree(p_root); }