static void cpu_vblankreset(void) { int cpunum; /* read hi scores from disk */ hs_update(); /* read keyboard & update the status of the input ports */ update_input_ports(); /* reset the cycle counters */ for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++) { if (!(cpu[cpunum].suspend & SUSPEND_REASON_DISABLE)) cpu[cpunum].iloops = Machine->drv->cpu[cpunum].vblank_interrupts_per_frame - 1; else cpu[cpunum].iloops = -1; } }
static void deleteOneDHistCB(Widget w, nTuBrowserInfo *nTuBrDummy, caddr_t call_data) { int i, idPos, *posList, count, id, uid, jn; nTuBrowserInfo *nTuBr; nTuBroHs1D *nTuH1; if (!XmListGetSelectedPos(OneDHistHistoListW, &posList, &count)) { DialogF(DF_WARN, OneDHistShellW, 1, "Please select a Histogram", "Acknowledged"); return; } id = OneDHistListedIDs[((*posList) -1)]; CurrentHistoUID = hs_uid(id); nTuBr = oneDHistNTupleSource(id); if (nTuBr == NULL) { DialogF(DF_ERR, OneDHistShellW, 1, "Internal Error in deleteOneDHist\nPlease report", "Acknowledged"); return; } hs_delete(id); hs_update(); for (i=0; i<nTuBr->sizeOfLists; i++) { if (nTuBr->hsItemList[i] == NULL) continue; if (id == nTuBr->hsItemList[i]->id ) { nTuH1 = (nTuBroHs1D *) nTuBr->hsItemList[i]; if (nTuH1->varIndices != NULL) free(nTuH1->varIndices); free(nTuH1); nTuBr->hsItemList[i] = NULL; break; } } nTuBr->nHistoItems--; nTuBr->nHisto1D--; redisplay1DHistoList(); }
/** * A function which changes the size of the hash table * and rehashes all the values currently present in the old hash table * to the new hash table using the updated hash functions. Among others, * this function also updates the value of the stree->tedge_size. * * @param * new_size The desired new size of the hash table. * When this function successfully finishes, it will be set * to the actual new size of the hash table. * @param * text the actual underlying text of the suffix tree * @param * stree the actual suffix tree * * @return On successful reallocation, this function returns 0. * If an error occurs, a positive error number is returned. */ int stree_shti_ht_rehash (size_t *new_size, const character_type *text, suffix_tree_shti *stree) { static const size_t max_rehash_attempts = 1024; /* the first part of the current hash key */ signed_integral_type source_node = 0; /* the second part of the current hash key */ character_type letter = 0; /* the current value in the hash table */ signed_integral_type target_node = 0; /* the original size of the hash table */ size_t original_tedge_size = stree->tedge_size; /* the original hash table data */ edge_record *original_tedge = stree->tedge; size_t original_new_size = (*new_size); size_t i = 0; size_t attempt_number = 0; int rehash_failed = 0; /* * The memory pointed to by stree->tedge is not lost * by the following call(s) to free and calloc, * because it has already been stored as the original_tedge. * * We set it to NULL at first in order to be able to easily allocate * the new memory without worrying about unintentionally freeing * the memory for the current hash table. In fact, we need * what's currently stored in it to create the new hash table * with the same content. */ stree->tedge = NULL; fprintf(stderr, "The rehashing of the hash table will now start.\n"); /* we will be trying to rehash the hash table until we succeed */ do { if (attempt_number == max_rehash_attempts) { fprintf(stderr, "Error: The maximum number of " "attempts to rehash\nthe hash " "table (%zu) has been reached!\n" "The rehash operation has failed " "permanently!\n", max_rehash_attempts); return (1); } ++attempt_number; fprintf(stderr, "Attempt number %zu:\n", attempt_number); rehash_failed = 0; (*new_size) = original_new_size; /* * We update the current hash settings with respect to * the current hash table size. */ if (hs_update(0, new_size, stree->hs) != 0) { fprintf(stderr, "Error: Can not correctly update " "the hash table settings.\n"); return (2); } /* * We deallocate the memory used by the previous attemt * to rehash the hash table. * * it is always safe to delete the NULL pointer, * so we need not to check for it */ free(stree->tedge); stree->tedge = NULL; /* * And now we allocate the new, cleared memory * for the hash table itself. * Note that due to the random access to the hash table, * it is essential that the memory is cleared * before begin used. That's why we use calloc * instead of realloc with stree->tedge set to NULL. * The call to realloc with the first argument * set to NULL is equivalent to malloc, * which does not clear the memory. */ stree->tedge = calloc((*new_size), sizeof (edge_record)); if (stree->tedge == NULL) { perror("calloc(stree->tedge)"); /* resetting the errno */ errno = 0; return (3); } else { /* * Despite that the call to the calloc seems * to have been successful, we reset the errno, * because at least on Mac OS X * it might have changed. */ errno = 0; } stree->tedge_size = (*new_size); /* * we reset the number of edges to zero, * as every insertion increases their number */ stree->edges = 0; for (i = 0; i < original_tedge_size; ++i) { /* if the original hash table record is not empty */ if (er_empty(original_tedge[i]) == 0) { source_node = original_tedge[i].source_node; target_node = original_tedge[i].target_node; if (stree_shti_edge_letter(source_node, &letter, target_node, text, stree) > 0) { fprintf(stderr, "Error: Could not get " "the first letter\n" "of an edge P(%d)--" "\"?\"-->C(%d). " "Exiting!\n", source_node, target_node); return (4); } /* * we insert the same hash table record * to the new hash table at a new position */ if (stree_shti_ht_insert(source_node, letter, target_node, 0, text, stree) != 0) { fprintf(stderr, "Error: Insertion " "of the edge " #ifdef SUFFIX_TREE_TEXT_WIDE_CHAR "P(%d)--\"%lc...\"-->C(%d)" #else "P(%d)--\"%c...\"-->C(%d)" #endif " failed permanently!\n" "This is very unfortunate, " "as we can not continue\n" "to rehash the hash table. " "We will start over again!\n", source_node, letter, target_node); rehash_failed = 1; break; } } } } while (rehash_failed == 1); /* * it is always safe to delete the NULL pointer, * so we need not to check for it */ free(original_tedge); original_tedge = NULL; fprintf(stderr, "Current hash table size:\n%zu cells of %zu " "bytes (totalling %zu bytes, ", stree->tedge_size, stree->er_size, stree->tedge_size * stree->er_size); print_human_readable_size(stderr, stree->tedge_size * stree->er_size); fprintf(stderr, ").\nThe rehashing of the hash table is complete.\n"); return (0); }
static void createOneDHistActual(int newHisto) { int countHisto, countNTu, countVar, ivar, ivarH, nBins, idh, uid, im, jn; int i, index, k, *ivk, ll, lastFixed; float from, to; double dfrom, dto; XmString *selectedItems; int *posListHisto, *posListNTu, *posListVar; char *str, category[24], x_label[20]; nTuDDL *ddl; descrGenNtuple *dNTu; nTuBrowserInfo *nTuBr; varGenNtuple *var; Arg args[2]; nTuBroHs1D *nTuH1; char *cDat; long pp; if (HistoIsBrowserNtuInit == NULL) { hs_initialize("Mcfio Ntuple Browser"); hs_histoscope(1); HistoIsBrowserNtuInit = 1; XtSetSensitive(McfioHsResetBtnW, True); hs_update(); setTimer(500); } nTuBr = CurrentNTupleBrowserSelected; ddl = mcf_GetNTuByPtrID(CurrentNTupleBrowserSelected->id); if (ddl->descrNtu == NULL) dNTu = ddl->reference->descrNtu; else dNTu = ddl->descrNtu; if (!XmListGetSelectedPos(OneDHistVariableListW, &posListVar, &countVar)) { DialogF(DF_WARN, OneDHistShellW, 1, "Please select a Variable", "Acknowledged"); return; } ivarH = (*posListVar) - 1; ivar = ivarH -1; /* ** Get how many time we have to histogram the variable */ if (ivar < dNTu->firstIndexed) im = -1; else { str = XmTextGetString(OneDHistMultW); if (GetIntText(OneDHistMultW, &im) == TEXT_READ_OK) { if (im > dNTu->maxMultiplicity) { DialogF(DF_WARN, OneDHistShellW, 1, "Incorrect instance, above maximum Multiplicty.","Acknowledged"); return; } else im--; } else { if ((strcmp(str,"All") == 0) || (strcmp(str,"ALL") == 0) || (strcmp(str,"all") == 0)) im = -1; else if ((strcmp(str,"First") == 0) || (strcmp(str,"FIRST") == 0) || (strcmp(str,"first") == 0)) im = 0; else if ((strcmp(str,"Second") == 0) || (strcmp(str,"SECOND") == 0) || (strcmp(str,"second") == 0)) im = 1; else if ((strcmp(str,"Third") == 0) || (strcmp(str,"THIRD") == 0) || (strcmp(str,"third") == 0)) im = 2; else { DialogF(DF_WARN, OneDHistShellW, 1, "Incorrect instance, please use a number","Acknowledged"); return; } } } /* ** We now read out the widget and define the histogram */ str = XmTextGetString(OneDHistTitleW); if (GetIntTextWarn(OneDHistNumBinsW, &nBins, "Number of Bins", TRUE) != TEXT_READ_OK) return; if (GetFloatTextWarn(OneDHistLowBinW, &dfrom, "Low Bin Edge", TRUE) != TEXT_READ_OK) return; if (GetFloatTextWarn(OneDHistHighBinW, &dto, "High Bin Edge", TRUE) != TEXT_READ_OK) return; from = (float) dfrom; to = (float) dto; /* ** At the beginning, the HistoList has a dummy item */ if (FirstOneDHistogram) uid = 1; else if (newHisto) { XtSetArg (args[0], XmNitemCount, &uid); XtGetValues(OneDHistHistoListW, args, 1); uid++; } else uid = CurrentHistoUID; if (ivarH == 0) strcpy(x_label,"Multiplicity"); else { var = dNTu->variables[ivar]; if(strlen(var->name) < 17) strcpy(x_label,var->name); else { strncpy(x_label,var->name,16); strcpy(&x_label[16],"..."); } } idh = hs_create_1d_hist(uid, str, "OneDHist", x_label, "Yield", nBins, from, to); XtFree(str); /* ** Store the idh, we need it for filling. Find the first free place on ** the list. */ if (nTuBr->nHistoItems == nTuBr->sizeOfLists) mcfioC_ExtendBrowserAnalysis(nTuBr); nTuH1 = (nTuBroHs1D *) malloc(sizeof(nTuBroHs1D)); index=0; while (nTuBr->hsItemList[index] != NULL) index++; nTuBr->hsItemList[index] = (nTuBroHsGeneral *) nTuH1; nTuBr->nHistoItems++; nTuBr->nHisto1D++; nTuH1->id = idh; nTuH1->type = HS_1D_HISTOGRAM; nTuH1->varNumber = ivarH; nTuH1->subBlock = im; nTuH1->varIndices = NULL; if(dNTu->firstIndexed == -1) lastFixed = dNTu->numVariables; else lastFixed = dNTu->firstIndexed; if (ivarH != 0) { var = dNTu->variables[ivar]; if (var->numDim >= 1) { nTuH1->varIndices= (int *) malloc(sizeof(int) * var->numDim); ivk = nTuH1->varIndices; getVarIndexDialog(ivk, var->numDim, var->dimensions); } } if (nTuBr->data == NULL) mcfioC_createBrowserData(nTuBr); cDat = (char *) nTuBr->data; if (ivarH == 0) { cDat += dNTu->multOffset; nTuH1->lDat = (long *) cDat; } else { if (ivar < lastFixed) { pp = ((long) nTuBr->data) + dNTu->variables[ivar]->offset; nTuH1->lDat = (long *) pp; } else nTuH1->lDat = NULL; /* A specific subVariable (leaf), we'll compute the data pointer at filling time */ } XtSetSensitive(OneDHistModifyW, True); XtSetSensitive(OneDHistDeleteW, True); redisplay1DHistoList(); FirstOneDHistogram = False; hs_update(); }